与按钮的宽度采用Android的重量相对布局 [英] Android relative layout with button width using weight
本文介绍了与按钮的宽度采用Android的重量相对布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用了 layout_weight
参数来设置按钮的宽度的总布局宽度的70%,但似乎我失去了一些重要的细节为了使其工作。
(另一种解决方案是用 display.getWidth()
编程工作,但它也不管用,因为我不知道我的.xml应看起来如果我选择设置宽度 button.setWidth()
)
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_height =FILL_PARENT
机器人:layout_width =FILL_PARENT
机器人:layout_weight =1.0>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =15px的
机器人:ID =@ + ID / userVersionTextViewNew
机器人:重力=中心
机器人:layout_centerVertical =真/>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =15px的
机器人:重力=中心
机器人:layout_above =@ ID / userVersionTextViewNew
机器人:ID =@ + ID / userSoftSerialNumberTextView/>
< ImageView的
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@可绘制/ logo_200
机器人:layout_above =@ ID / userSoftSerialNumberTextView
机器人:layout_centerHorizontal =真/>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =15px的
机器人:重力=中心
机器人:layout_below =@ ID / userVersionTextViewNew
机器人:ID =@ + ID / dummyTextView/>
<按钮
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / loginButton
机器人:文本=Σύνδεση
机器人:layout_centerHorizontal =真
机器人:layout_below =@ ID / dummyTextView
机器人:layout_weight =0.7/>
<按钮
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / demoLoginButton
机器人:文本=Δοκιμαστικήχρήση
机器人:layout_centerHorizontal =真
机器人:layout_below =@ ID / loginButton
机器人:layout_weight =0.7/>
< / RelativeLayout的>
解决方案
试试这个..
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_height =FILL_PARENT
机器人:layout_width =FILL_PARENT>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =15px的
机器人:ID =@ + ID / userVersionTextViewNew
机器人:重力=中心
机器人:layout_centerVertical =真/>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =15px的
机器人:重力=中心
机器人:layout_above =@ ID / userVersionTextViewNew
机器人:ID =@ + ID / userSoftSerialNumberTextView/>
< ImageView的
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@可绘制/ logo_200
机器人:layout_above =@ ID / userSoftSerialNumberTextView
机器人:layout_centerHorizontal =真/>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSIZE =15px的
机器人:重力=中心
机器人:layout_below =@ ID / userVersionTextViewNew
机器人:ID =@ + ID / dummyTextView/>
<的LinearLayout
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =FILL_PARENT
机器人:重力=center_horizontal
机器人:layout_below =@ ID / dummyTextView
机器人:ID =@ + ID / loginButtonLayout
机器人:weightSum =1.0>
<按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / loginButton
机器人:文本=Σύνδεση
机器人:layout_weight =0.7/>
< / LinearLayout中>
<的LinearLayout
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =FILL_PARENT
机器人:重力=center_horizontal
机器人:layout_below =@ ID / loginButtonLayout
机器人:weightSum =1.0>
<按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / demoLoginButton
机器人:文本=Δοκιμαστικήχρήση
机器人:layout_weight =0.7/>
< / LinearLayout中>
< / RelativeLayout的>
I've used the layout_weight
parameter to set the width of the buttons at 70% of the total layout width, but it seems I'm missing some important detail in order to make it work.
(Another solution would be to work with display.getWidth()
programmatically, but it doesn't work either, because I don't know what my .xml should look like If I choose to set the width with button.setWidth()
)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1.0">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:id="@+id/userVersionTextViewNew"
android:gravity="center"
android:layout_centerVertical="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:gravity="center"
android:layout_above="@id/userVersionTextViewNew"
android:id="@+id/userSoftSerialNumberTextView"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/logo_200"
android:layout_above="@id/userSoftSerialNumberTextView"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:gravity="center"
android:layout_below="@id/userVersionTextViewNew"
android:id="@+id/dummyTextView"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/loginButton"
android:text="Σύνδεση"
android:layout_centerHorizontal="true"
android:layout_below="@id/dummyTextView"
android:layout_weight="0.7"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/demoLoginButton"
android:text="Δοκιμαστική χρήση"
android:layout_centerHorizontal="true"
android:layout_below="@id/loginButton"
android:layout_weight="0.7"/>
</RelativeLayout>
解决方案
Try This..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:id="@+id/userVersionTextViewNew"
android:gravity="center"
android:layout_centerVertical="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:gravity="center"
android:layout_above="@id/userVersionTextViewNew"
android:id="@+id/userSoftSerialNumberTextView"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/logo_200"
android:layout_above="@id/userSoftSerialNumberTextView"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:gravity="center"
android:layout_below="@id/userVersionTextViewNew"
android:id="@+id/dummyTextView"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity = "center_horizontal"
android:layout_below="@id/dummyTextView"
android:id="@+id/loginButtonLayout"
android:weightSum="1.0">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/loginButton"
android:text="Σύνδεση"
android:layout_weight="0.7"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity = "center_horizontal"
android:layout_below="@id/loginButtonLayout"
android:weightSum="1.0">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/demoLoginButton"
android:text="Δοκιμαστική χρήση"
android:layout_weight="0.7"/>
</LinearLayout>
</RelativeLayout>
这篇关于与按钮的宽度采用Android的重量相对布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文