LinearLayout 不会显示所有内容
我的问题看似简单,但我真的无法解决。在某些时候,我的代码会在 AlertDialog
内的 LinearLayout
中显示一堆图像 (ImageView
)。 问题是并没有显示所有内容。
这是我的代码:
public LinearLayout createLayout(String text) {
LinearLayout ll = new LinearLayout(this.c);
int res;
for(int i=0; i<text.length(); ++i) {
res = this.c.getResources().getIdentifier("pigpen_" + Character.toLowerCase(text.charAt(i)), "drawable", this.c.getPackageName());
ImageView iv = new ImageView(this.c);
iv.setPadding(5, 0, 0, 5);
iv.setImageResource(res);
ll.addView(iv);
}
return ll;
}
DialogAlert 的代码:
protected ResultDialog(final Context context, CharSequence title, LinearLayout ll) {
super(context);
ll.setPadding(10, 5, 10, 5);
this.setView(ll);
this.setTitle(title);
}
正如您所看到的,结果并不好。你知道为什么吗?
My problem might seems easy, but I really can't resolve it. At some point, my code displays a bunch of images (ImageView
) in a LinearLayout
, inside an AlertDialog
.
The problem is that not everything is displayed.
Here's my code :
public LinearLayout createLayout(String text) {
LinearLayout ll = new LinearLayout(this.c);
int res;
for(int i=0; i<text.length(); ++i) {
res = this.c.getResources().getIdentifier("pigpen_" + Character.toLowerCase(text.charAt(i)), "drawable", this.c.getPackageName());
ImageView iv = new ImageView(this.c);
iv.setPadding(5, 0, 0, 5);
iv.setImageResource(res);
ll.addView(iv);
}
return ll;
}
And the code for the DialogAlert :
protected ResultDialog(final Context context, CharSequence title, LinearLayout ll) {
super(context);
ll.setPadding(10, 5, 10, 5);
this.setView(ll);
this.setTitle(title);
}
And as you can see, the result is not good. Do you have any idea why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是您的
LinearLayout
没有任何尺寸。宽度和高度都是 0。所以一切都很完美。您缺少对 setLayoutParams 的调用,仅此而已。
The problem is that your
LinearLayout
does not have any dimensions. Width and height are 0. So everything works perfectly.You are lacking a call to setLayoutParams, that's all.
您可以使用 HorizontalScrollView 包装 LinearLayout。这样您就可以添加大量图像并滚动以查看全部图像。
You can wrap your LinearLayout with an HorizontalScrollView. That way you can add a lot of images and scroll to view them all.
ImageAdapter 类:
公共类 ImageAdapter 扩展 BaseAdapter 实现 ListAdapter {
私有上下文c;
私有ArrayList alImages;
Et ma classe ImageAdapter :
public class ImageAdapter extends BaseAdapter implements ListAdapter {
private Context c;
private ArrayList alImages;