Android 带百分比空白的线性布局
我正在为我的简单android应用程序设计线性布局。我想根据大小动态更改两个视图的部分(我想要的,对于从左到右的一行,前20%为空,所有内容都在其余80%内)。对于这种方法,我选择了不同视图的权重。我为这种方法创建了一个嵌套的线性布局。例如,布局层次结构如下所示Android 带百分比空白的线性布局,android,android-layout,layout,Android,Android Layout,Layout,我正在为我的简单android应用程序设计线性布局。我想根据大小动态更改两个视图的部分(我想要的,对于从左到右的一行,前20%为空,所有内容都在其余80%内)。对于这种方法,我选择了不同视图的权重。我为这种方法创建了一个嵌套的线性布局。例如,布局层次结构如下所示 <linearLayout> //parent layout <linearLayout //child 1 layout android:layout_weight="1">
<linearLayout> //parent layout
<linearLayout //child 1 layout
android:layout_weight="1">
//so that this view occupy 20% of the space regardless the width of device. I intensionally wanna keep this view empty.
</linearLayout>
<linearLayout //child 2 layout
android:layout_weight="4">
//so that this view occupy 80% of the space regardless the width of device. and
//inside this view I have whatever view I wanna add on it.
<EditText>
<ImageView>
</linearLayout>
</linearLayout>
//父布局
//因此,无论设备的宽度如何,此视图都会占用20%的空间。我想让这个观点保持空白。
//因此,无论设备的宽度如何,该视图都占据了80%的空间。及
//在这个视图中,我有我想添加的任何视图。
通过这种方法,Android Studio中的Lint会告诉我以下警告:
线性布局
视图无效(无子视图,无背景
,无id
,无样式
)注意:您需要使用它。这是一种使用权重的可能解决方案:
<LinearLayout
android:layout_width="match_parent"
android:gravity="end"
android:weightSum="1">
<!-- Your content here: -->
<View
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_gravity="end" />
</LinearLayout>
这正是我想要的。谢谢