有没有办法使用与布局的宽度和高度都权重的方法 [英] Is there a way to use weights with both layout width and height
问题描述
我有有四个按钮US $ p $沿着垫使用布局的重量均匀地分布其中我的应用程序的底部布局。
我也希望使用相同的排序权重,以增加按钮的HIGHT
到目前为止,所有我可以看到无论是在计算与水平的LinearLayout或高度使用垂直的LinearLayout的宽度。
宽度是伟大的工作只是它的高度。
如果体重不能在同一时间如何设置的高度,使其相对的每一个屏幕大小。使用
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:weightSum =1.0
机器人:重力=底> <的ImageButton
机器人:ID =@ + ID / Button1的
机器人:layout_width =FILL_PARENT
机器人:layout_height =80dp
机器人:layout_weight =0.25
机器人:SRC =@绘制/ B1
机器人:文字=左/> <的ImageButton
机器人:ID =@ + ID / Button2的
机器人:layout_width =FILL_PARENT
机器人:layout_height =80dp
机器人:layout_weight =0.25
机器人:SRC =@绘制/ B2
机器人:文字=ROTL/> <的ImageButton
机器人:ID =@ + ID /按钮3
机器人:layout_width =FILL_PARENT
机器人:layout_height =80dp
机器人:layout_weight =0.25
机器人:SRC =@绘制/ B3
机器人:文字=ROTR/> <的ImageButton
机器人:ID =@ + ID /将Button4
机器人:layout_width =FILL_PARENT
机器人:layout_height =80dp
机器人:layout_weight =0.25
机器人:SRC =@绘制/ B4
机器人:文字=右/> < / LinearLayout中>
我不想硬code按钮的高度
- 设置你的
按钮
s'的高度,以FILL_PARENT
- 将您的横向
的LinearLayout
在垂直的LinearLayout
- 设置在横向
的LinearLayout
的体重< - 这现在是一个垂直的重量,会影响你的按钮
s'的高度
按钮应正确调整
I have a layout which has four buttons spread along the bottom of my app using the layout weight to distribute them evenly.
I also want to increase the hight of the buttons using the same sort of weighting.
So far all i can see is either calculating the width with a horizontal linearlayout or height using a vertical linearlayout.
the width is working great its just the height.
If the weight cannot be used at the same time how can i set the height so that it is relative on every screen size.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1.0"
android:gravity="bottom">
<ImageButton
android:id="@+id/Button1"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_weight="0.25"
android:src="@drawable/b1"
android:text="Left" />
<ImageButton
android:id="@+id/Button2"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_weight="0.25"
android:src="@drawable/b2"
android:text="RotL" />
<ImageButton
android:id="@+id/Button3"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_weight="0.25"
android:src="@drawable/b3"
android:text="RotR" />
<ImageButton
android:id="@+id/Button4"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_weight="0.25"
android:src="@drawable/b4"
android:text="Right" />
</LinearLayout>
I dont want to hardcode the heights of the buttons
- Set your
Button
s' heights tofill_parent
- Place your horizontal
LinearLayout
in a verticalLinearLayout
- Set the horizontal
LinearLayout
's weight <- this is now a vertical weight that will affect yourButton
s' heights
The buttons should resize correctly
这篇关于有没有办法使用与布局的宽度和高度都权重的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!