里面DraggableGridView显示布局 [英] Displaying layouts inside DraggableGridView
问题描述
我试图使图片+标题对的电网,用户将能够通过拖放放重新排列;下降。要做到这一点,我使用DraggableGridView - 。 https://github.com/thquinn/DraggableGridView
虽然我可以显示TextViews和ImageViews和重新排列,那一刻我尝试将它们连接在一个布局都停止显示。
所以,图像和字幕解析XML之后,这个作品:
为(ImagePair对:对){
电视=新的TextView(本);
tv.setText(pair.getText()); URL = IMAGEURL新的URL(pair.getURL());
BMP位图= BitmapFactory.de codeStream(imageURL.openConnection()的getInputStream());
IMV =新ImageView的(本);
imv.setImageBitmap(BMP); dgv.addView(电视);
dgv.addView(IMV);
和它显示文本和图像的网格,但它们未配对 - 可以切换文本的地方与图像等
。当我尝试插入包含图像+文字布局:
为(ImagePair对:对){ BMP位图= BitmapFactory.de codeStream(imageURL.openConnection()的getInputStream()); LayoutInflater李= getLayoutInflater();
视图V = li.inflate(R.layout.image,NULL); TextView的txtv =(TextView中)v.findViewById(R.id.ltext); txtv.setText(pair.getText()); ImageView的IV =(ImageView的)v.findViewById(R.id.limage);
iv.setImageBitmap(BMP); dgv.addView(五);
没有显示。我可以做任何显示单一视图
this.setContentView(V);
和它会正确显示图像+标题对,而是试图将它们插入到黑屏电网结果,尽管电网报告9名儿童present。
我使用的布局:
<?XML版本=1.0编码=UTF-8&GT?;
< TableLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>
<的TableRow的android:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT> < ImageView的
机器人:ID =@ + ID / limage
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< / ImageView的> < /&的TableRow GT; <的TableRow的android:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT> <的TextView
机器人:ID =@ + ID / LTEXT
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=TextView的
机器人:重力=CENTER_HORIZONTAL
机器人:textColorHighlight =#656565>
< / TextView的>
< /&的TableRow GT;< / TableLayout>
添加code中的一行DraggableGridView.java解决问题。打开DraggableGridView.java并添加以下行
getChildAt(I).measure(MeasureSpec.makeMeasureSpec(childSize,MeasureSpec.EXACTLY),MeasureSpec.makeMeasureSpec(childSize,MeasureSpec.EXACTLY));
在
getChildAt(I).layout(xy.x,xy.y,xy.x + childSize,xy.y + childSize);
希望有所帮助。
从另一个帖子的链接找到解决办法:<一href=\"http://stackoverflow.com/questions/13699426/imageview-and-textview-not-displaying-in-view\">Imageview而TextView的不是视图中显示?
I'm trying to make a Grid of Image + caption pairs, that the user will be able to rearrange by drag&drop. To do this I'm using DraggableGridView - https://github.com/thquinn/DraggableGridView .
While I can display TextViews and ImageViews and rearrange them, the moment I try to connect them in one layout everything stops displaying.
So after parsing an XML with images and captions this works:
for(ImagePair pair : pairs){
tv = new TextView(this);
tv.setText(pair.getText());
URL imageURL = new URL(pair.getURL());
Bitmap bmp = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
imv = new ImageView(this);
imv.setImageBitmap(bmp);
dgv.addView(tv);
dgv.addView(imv);
And it displays a grid of Texts and Images, but they are not paired - you can switch the place of text with an image etc.
When I try inserting a Layout containing an Image+ Text:
for(ImagePair pair : pairs){
Bitmap bmp = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
LayoutInflater li = getLayoutInflater();
View v = li.inflate(R.layout.image, null);
TextView txtv = (TextView)v.findViewById(R.id.ltext);
txtv.setText(pair.getText());
ImageView iv = (ImageView)v.findViewById(R.id.limage);
iv.setImageBitmap(bmp);
dgv.addView(v);
Nothing displays. I can display any single view by doing
this.setContentView(v);
And it will display a image+caption pair properly, but trying to insert them into the grid results in a black screen, despite the grid reporting 9 children present.
The layout I'm using:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/limage"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</TableRow>
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/ltext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:gravity="center_horizontal"
android:textColorHighlight="#656565">
</TextView>
</TableRow>
</TableLayout>
Adding one line of code in DraggableGridView.java fixes the problem. Open DraggableGridView.java and add the following line
getChildAt(i).measure(MeasureSpec.makeMeasureSpec(childSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(childSize, MeasureSpec.EXACTLY));
before
getChildAt(i).layout(xy.x, xy.y, xy.x + childSize, xy.y + childSize);
Hope that helps. Found solution from another post link:Imageview and textview not displaying in view?
这篇关于里面DraggableGridView显示布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!