1
在我的Android应用程序中,我弹出一个显示ListView的对话框。我遇到的问题是获取textview高度来填充父项。我希望它填充父项,然后垂直居中文本。相反,它似乎包裹了身高。下面是对话的XML:在对话框中无法获取TextView来填充ListView中的父级高度
<?xml version="1.0" encoding="utf-8"?>
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loadSwitcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff484a4a"
android:gravity="center"
android:orientation="vertical"
android:tag="LoadingView" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center" >
<ProgressBar
android:id="@+id/marker_progress"
style="?android:attr/progressBarStyle"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:indeterminate="true" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/msg_PleaseWait"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="ContentView" >
<TextView
android:id="@+id/tvHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:background="#7395bf"
android:padding="3dp"
android:text="@string/lbl_SelectLocationSet"
android:textColor="#ffffff"
android:textSize="18sp" />
<ListView
android:id="@+id/lvData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:background="#ff626262"
android:cacheColorHint="#00000000"
android:divider="#ff7f7f7f"
android:dividerHeight="1dp"
android:scrollingCache="true" />
<LinearLayout
android:id="@+id/llToolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#cacaca"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp" >
<Button
android:id="@+id/btnOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/lbl_ButtonOK"
android:textSize="16sp" />
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/lbl_ButtonCancel"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</ViewSwitcher>
,这里是在列表视图连续XML:
<?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" >
<RadioButton
android:id="@+id/rbSelected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:checked="false"
android:clickable="false"
android:paddingLeft="5dp" >
</RadioButton>
<ImageView
android:id="@+id/ivEncrypted"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginRight="6dp"
android:layout_toLeftOf="@id/rbSelected"
android:scaleType="fitXY"
android:src="@drawable/icon_lock_16x16" />
<TextView
android:id="@+id/tvDate"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:background="#baf5c7"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@id/ivEncrypted"
android:textColor="#ffffff"
android:textSize="18sp" />
</RelativeLayout>
从我自己的经验我知道,对话框的父视图将始终wrap_content,所以match_parent在子视图中没有效果。相反,你必须用dp单位做一些静态尺寸。这必须在多种屏幕尺寸下完成 – Opiatefuchs