Android中的线性布局间距
这是我的布局: 文本视图 IMAGEVIEW(可选) LINEARLAYOUT-动态添加按钮 线性布局-两个按钮并排(左按钮和右按钮) 我需要做什么来确保底部两个线性布局固定在屏幕底部,而不管它们可能占用多少空间?第一个线性布局可能有3个按钮,占据屏幕的一半以上,这是可以的。它只需要位于最后一个线性布局中的左/右按钮上方,该布局固定在底部 然后我希望我的文本视图和图像视图垂直居中于剩余空间。如果没有图像,ImageView将设置为不可见,因此它只能是需要居中的文本视图 我一直在玩android:gravity=“bottom”、android:layout\u height=“0dip”/android:layout\u weight=“1”(我后来意识到这只会给文本/图像视图和两个线性布局带来50%的效果),但我无法得到我想要的结果Android中的线性布局间距,android,android-linearlayout,Android,Android Linearlayout,这是我的布局: 文本视图 IMAGEVIEW(可选) LINEARLAYOUT-动态添加按钮 线性布局-两个按钮并排(左按钮和右按钮) 我需要做什么来确保底部两个线性布局固定在屏幕底部,而不管它们可能占用多少空间?第一个线性布局可能有3个按钮,占据屏幕的一半以上,这是可以的。它只需要位于最后一个线性布局中的左/右按钮上方,该布局固定在底部 然后我希望我的文本视图和图像视图垂直居中于剩余空间。如果没有图像,ImageView将设置为不可见,因此它只能是需要居中的文本视图 我一直在玩android:
非常感谢您的建议。您必须接受
相关建议。
。
这样可以更好地控制视图的相对位置,如下所示:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView"
android:layout_above="@+id/imageView"
android:layout_centerVertical="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/imageView"
android:layout_above="@+id/ll_1"
android:layout_centerVertical="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLyout
android:id="@+id/ll_1"
android:layout_above="@+id/ll_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLyout
android:id="@+id/ll_2"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
向我们显示您的确切代码..我需要做什么来确保底部的两个线性布局固定在屏幕底部-将所有视图包装在一个相对布局中
,带有两个按钮的线性布局将具有规则布局\u alignParentBottom
,另一个LinearLayout
将位于第一个LinearLayout
(layout_)的上方。将其余两个视图包装在另一个布局中,并将其放置在上页边距之间和动态线性布局上方。嗨,Luksprog,我已经尝试过这个(以及owe建议的)并且它很接近,但我发现,出于某种原因,顶部的文本视图是顶部对齐和左侧对齐的。理想情况下,我希望文本/图像一起居中对齐,但如果没有图像(即Visibility.GONE),则文本仍然居中对齐。我使用的代码是这样的:嗨,owe,我遵循了你的例子(以及Luksprog所说的),很接近,但不完全如此。我已经解释了正在发生的事情,以回应卢卡斯堡的回答。谢谢。请尝试以下操作:将LinearLayout
的layout\u width
和layout\u height
属性更改为wrap\u content
。同时将android:layout\u centerVertical=“true”
更改为android:layout\u centerInParent=“true”
。下面是一篇关于如何为视图内容使用gravity
属性的帖子: