单排FILL_PARENT ListView的高度 [英] Single row to fill_parent ListView height
问题描述
有在ListView一排,我想用相同的高度ListView控件(让我们说这是全屏幕)。
该行布局看起来像
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直> < ImageView的
机器人:ID =@ + ID / ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_centerHorizontal =真
机器人:layout_centerVertical =真
机器人:SRC =@绘制/错误/> <的TextView
机器人:ID =@ + ID / TextView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / ImageView的
机器人:layout_centerHorizontal =真
机器人:layout_marginTop =14dp
安卓了minHeight =30dip
机器人:textAppearance =机器人:ATTR / textAppearanceMedium/>
< / RelativeLayout的>
和适配器的getView是
@覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
查看排= inflater.inflate(R.layout.myrow,父母,假);
返回行;
}
卜已显示行一样将它与的android:layout_height =WRAP_CONTENT
布局preVIEW显示的行填充它的父和我使用膨胀(R.layout.myrow,父母,FALSE);
,ListView的肯定全屏显示,而行仅仅是作为图像+ TextView的。
我失去了一些重要的东西?
我有类似的问题,我想我已经解决,使报告在这里。
我在ListView中有更多行,但我想,该行的高度是一样的列表视图,从而不得占用布局的所有剩余空间。我行提出只是一个ImageView的的。我有以下问题:
- 我想要那个较小的图像扩大到占据所有空间
-Bigger图片不得超过exapnd行高更
如果我做了任何错误,请在此留言。
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =0dp
机器人:layout_weight =0.9
机器人:比重=中心
机器人:方向=垂直>
< ListView控件
机器人:ID =@ ID / lay_main_firma_objekti
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:比重=中心>
< /&的ListView GT;
< / LinearLayout中>
行布局:
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:比重=中心>
<的TextView
机器人:ID =@ + ID / XX
机器人:layout_width =match_parent
机器人:layout_height =match_parent/>
< ImageView的
机器人:ID =@ ID / imageView_obj
机器人:contentDescription =@字符串/ objektDesc
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_alignLeft =@ ID / XX
机器人:layout_alignTop =@ ID / XX
机器人:layout_alignRight =@ ID / XX
机器人:layout_alignBottom =@ ID / XX
机器人:scaleType =fitXY
机器人:SRC =@绘制/ custom_prazno/>
< / RelativeLayout的>
getView它是
重要然后在适配器
convertView.setMinimumHeight(parent.getMeasuredHeight());
ImageView的SLIKA =(ImageView的)v.findViewById(R.id.imageView_obj);
slika.setMinimumHeight(parent.getMeasuredHeight());
TextView的XX =(TextView中)v.findViewById(R.id.xx);
xx.setHeight(parent.getMeasuredHeight());
我觉得这是。
心连心
There's one row in the listView which I want to be with the same height as the listView (let's say that is full-screen).
The row layout looks like
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/error" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:minHeight="30dip"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</RelativeLayout>
And the adapter's getView is
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = inflater.inflate(R.layout.myrow, parent, false);
return row;
}
Bu the row is displayed the same as it would be with android:layout_height="wrap_content"
.
Layout preview shows the row filling it's parent and I'm using inflate(R.layout.myrow, parent, false);
, the listView is certainly displayed full-screen and the row is only as tall as the image + textView.
Am i missing something important ?
I had similar problem I think I have solved so reporting here.
I have more rows in my ListView, but I want that the row height be the same of the listview, which in turn shall occupy all the remaining space of the layout. My row is made of just one ImageView. I had problems with the following:
-I want that smaller images expand to occupy all the space -Bigger images shall not exapnd more than a row height
If I have made any error please leave a note here.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:gravity="center"
android:orientation="vertical">
<ListView
android:id="@id/lay_main_firma_objekti"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
</ListView>
</LinearLayout>
Row layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="@+id/xx"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@id/imageView_obj"
android:contentDescription="@string/objektDesc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@id/xx"
android:layout_alignTop="@id/xx"
android:layout_alignRight="@id/xx"
android:layout_alignBottom="@id/xx"
android:scaleType="fitXY"
android:src="@drawable/custom_prazno" />
</RelativeLayout>
Then in the Adapter getView it is important to
convertView.setMinimumHeight(parent.getMeasuredHeight());
ImageView slika=(ImageView)v.findViewById(R.id.imageView_obj);
slika.setMinimumHeight(parent.getMeasuredHeight());
TextView xx=(TextView)v.findViewById(R.id.xx);
xx.setHeight(parent.getMeasuredHeight());
I think that is. hth
这篇关于单排FILL_PARENT ListView的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!