布局功能的按钮,填写同样的屏幕尺寸 [英] Layout with buttons which fill screen size equally
本文介绍了布局功能的按钮,填写同样的屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要创建一个包含8个按键(四行,两连胜)。布局
我要的按钮按比例填充屏幕尺寸 - 等于利润因此会合身在diffrend屏幕尺寸
这是我现在有:
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>< RelativeLayout的
机器人:ID =@ + ID / TEST_1
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=横向
机器人:layout_marginLeft =10dp> <按钮
机器人:ID =@ + ID / concession_btn
机器人:layout_width =150dip
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/> <按钮
机器人:layout_width =150dip
机器人:layout_height =WRAP_CONTENT
机器人:layout_toRightOf =@ + ID / concession_btn
机器人:文字=TEST2
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/> <按钮
机器人:ID =@ + ID / test_2
机器人:layout_width =150dip
机器人:layout_below =@ + ID / concession_btn
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST3
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/> <按钮
机器人:layout_width =150dip
机器人:layout_toRightOf =@ + ID / test_2
机器人:layout_below =@ + ID / concession_btn
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST4
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/>
<按钮
机器人:ID =@ + ID / test_3
机器人:layout_width =150dip
机器人:layout_below =@ + ID / test_2
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST3
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/> <按钮
机器人:layout_width =150dip
机器人:layout_toRightOf =@ + ID / test_3
机器人:layout_below =@ + ID / test_2
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST4
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/>
<按钮
机器人:ID =@ + ID / test_4
机器人:layout_width =150dip
机器人:layout_below =@ + ID / test_3
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST3
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/> <按钮
机器人:layout_width =150dip
机器人:layout_toRightOf =@ + ID / test_4
机器人:layout_below =@ + ID / test_3
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST4
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/>
< / RelativeLayout的>
这给了我八个按钮 - 在一排四排二,但我的XML使用固定的利润率所以不会FITT上也指出错误的屏幕尺寸
。帮助将非常AP preciated!
解决方案
//尝试这种方式,希望这将帮助你...< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
机器人:填充=5DP> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT> <按钮
机器人:ID =@ + ID / concession_btn
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:文字=测试1
机器人:背景=@绘制/ myButton的/> <按钮
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST2
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/>
< / LinearLayout中> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT> <按钮
机器人:ID =@ + ID / test_2
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST3
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/> <按钮
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST4
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/>
< / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT> <按钮
机器人:ID =@ + ID / test_3
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST5
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/> <按钮
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST6
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/>
< / LinearLayout中> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT> <按钮
机器人:ID =@ + ID / test_4
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:文字=TEST7
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/> <按钮
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:文字=test8
机器人:layout_weight =1
机器人:背景=@绘制/ myButton的/>
< / LinearLayout中>
< / LinearLayout中>
I want to create a layout which consist of 8 buttons (four rows, two in a row).
I want the buttons to fill the screen size proportionally - equal margins so it will fit well on diffrend screen sizes.
This is what i have now:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/test_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_marginLeft="10dp" >
<Button
android:id="@+id/concession_btn"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/mybutton" />
<Button
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/concession_btn"
android:text="test2"
android:layout_weight="1"
android:background="@drawable/mybutton" />
<Button
android:id="@+id/test_2"
android:layout_width="150dip"
android:layout_below="@+id/concession_btn"
android:layout_height="wrap_content"
android:text="test3"
android:layout_weight="1"
android:background="@drawable/mybutton"/>
<Button
android:layout_width="150dip"
android:layout_toRightOf="@+id/test_2"
android:layout_below="@+id/concession_btn"
android:layout_height="wrap_content"
android:text="test4"
android:layout_weight="1"
android:background="@drawable/mybutton" />
<Button
android:id="@+id/test_3"
android:layout_width="150dip"
android:layout_below="@+id/test_2"
android:layout_height="wrap_content"
android:text="test3"
android:layout_weight="1"
android:background="@drawable/mybutton"/>
<Button
android:layout_width="150dip"
android:layout_toRightOf="@+id/test_3"
android:layout_below="@+id/test_2"
android:layout_height="wrap_content"
android:text="test4"
android:layout_weight="1"
android:background="@drawable/mybutton" />
<Button
android:id="@+id/test_4"
android:layout_width="150dip"
android:layout_below="@+id/test_3"
android:layout_height="wrap_content"
android:text="test3"
android:layout_weight="1"
android:background="@drawable/mybutton"/>
<Button
android:layout_width="150dip"
android:layout_toRightOf="@+id/test_4"
android:layout_below="@+id/test_3"
android:layout_height="wrap_content"
android:text="test4"
android:layout_weight="1"
android:background="@drawable/mybutton" />
</RelativeLayout>
Which gives me eight buttons - four rows two in a row, but my xml uses fix margins so it will not fitt well on diffrent screen sizes.
Help will be much appreciated!
解决方案
// try this way,hope this will help you...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/concession_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="test1"
android:background="@drawable/mybutton" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="test2"
android:layout_weight="1"
android:background="@drawable/mybutton" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/test_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="test3"
android:layout_weight="1"
android:background="@drawable/mybutton"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="test4"
android:layout_weight="1"
android:background="@drawable/mybutton" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/test_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="test5"
android:layout_weight="1"
android:background="@drawable/mybutton"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="test6"
android:layout_weight="1"
android:background="@drawable/mybutton" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/test_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="test7"
android:layout_weight="1"
android:background="@drawable/mybutton"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="test8"
android:layout_weight="1"
android:background="@drawable/mybutton" />
</LinearLayout>
</LinearLayout>
这篇关于布局功能的按钮,填写同样的屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文