Android 如何强制LinearLayout中的元素显示其内容?即使之前的元素具有fill_父参数?
我一直在努力解决这些布局问题: [任何应使用所有左空格的自定义视图|视图|] [视图1 |任何应使用AllLeftSpace的客户视图|视图2] 如果AnyCustoViewWhichShouldTakeAllLeftSpace具有参数match\u parent或fill\u parent,则视图或视图2不可见,因为没有剩余空间 有人建议将CustomView的权重设为1,以便最终让该视图呈现。但这并非在所有情况下都有效 Android中是否有类似于XAML/C#/WPF的东西?例如width=*(获取所有您获取的内容,但不获取更多)Android 如何强制LinearLayout中的元素显示其内容?即使之前的元素具有fill_父参数?,android,view,android-linearlayout,Android,View,Android Linearlayout,我一直在努力解决这些布局问题: [任何应使用所有左空格的自定义视图|视图|] [视图1 |任何应使用AllLeftSpace的客户视图|视图2] 如果AnyCustoViewWhichShouldTakeAllLeftSpace具有参数match\u parent或fill\u parent,则视图或视图2不可见,因为没有剩余空间 有人建议将CustomView的权重设为1,以便最终让该视图呈现。但这并非在所有情况下都有效 Android中是否有类似于XAML/C#/WPF的东西?例如width
有没有关于好的布局结构的好教程,可以解决这类问题 您能否详细说明权重为1的CustomView在哪些情况下不适合您? 假设视图1和视图2为固定高度,则执行以下操作
<LinearLayout
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="100px"
android:background="#ff0000"
/>
<View
android:id="@+id/customview
android:layout_width="fill_parent"
android:background="#00ff00"
android:layout_weight="1"
/>
<View
android:id="@+id/view2"
android:layout_width="fill_parent"
android:layout_height="100px"
android:background="#0000ff"
/>
</LinearLayout>
尝试使用下面的代码
<LinearLayout
android:id="@+id/container"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="100px"
android:background="#ff0000"/>
<View
android:id="@+id/emptyView"
android:layout_width="fill_parent"
android:layout_height="100px"
android:layout_weight="1"/>
<View
android:id="@+id/view2"
android:layout_width="fill_parent"
android:layout_height="100px"
android:background="#0000ff"/>
</LinearLayout>
在渲染view1
和view2
之后,中间视图将占用剩余的所有空间。是否要先给view1和view2留出空间,然后再给任何需要占用所有leftspace的客户留出空间?是!就是这样;)嘿谢谢我可能在实施过程中犯了一个错误。我无法重现“重量”不是解决方案的布局。所以我接受你的回答。干杯