Android ViewFlipper width正在包装其内容,而填充父对象不起作用
以下是我的布局XML:Android ViewFlipper width正在包装其内容,而填充父对象不起作用,android,xml,layout,viewflipper,fill-parent,Android,Xml,Layout,Viewflipper,Fill Parent,以下是我的布局XML: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableLayout android:layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="true">
<TableRow
android:background="#FF0000">
<ViewFlipper
android:id="@+id/viewer_something"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCCCCC">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button one" />
</LinearLayout>
<LinearLayout
android:id="@+id/view2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button two" />
</LinearLayout>
</ViewFlipper>
</TableRow>
<TableRow
android:background="#FF0000">
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button three" />
</TableRow>
</TableLayout>
</LinearLayout>
简言之,我在一个表格行中有一个ViewFlipper。ViewFlipper正在缩小到其内容的大小,即使所有元素都已指定填充父元素。在下面的屏幕截图中,ViewFlipper的背景为灰色,TableRows的背景为红色
在你的ViewFlipper上设置
android:layout\u weight=“1”
就可以了。确实可以。我不明白它为什么起作用,但它起作用了。你能解释一下吗?假设你有一个包含各种子视图的父视图。如果将每个子视图设置为包裹内容,然后指定布局权重,则每个视图都将按其权重占总权重的比例展开填充剩余空白。因此,如果父视图(LinearLayout)中只有一个视图(ViewFlipper),则设置布局权重将使其填充其余的空白。这就是布局权重起作用的原因;至于为什么在宽度上填充不起作用,我不是很确定,但这可能是测量尚未绘制的视图的问题。谢谢。我仍然困惑于为什么填充家长一开始不起作用-就像你说的-但我现在明白为什么添加布局权重会增加额外的保险,它会填充所有内容。