指定宽度的一半可用屏幕宽度声明 [英] Assign width to half available screen width declaratively

查看:117
本文介绍了指定宽度的一半可用屏幕宽度声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能一个小部件的宽度分配给一半的可用屏幕宽度,并使用XML的声明做呢?

Is it possible to assign a widget width to half the available screen width, and do it using declarative xml?

推荐答案

如果您的小部件是一个按钮:

If your widget is a Button:

<LinearLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="2"
    android:orientation="horizontal">
    <Button android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="somebutton">

    <TextView android:layout_width="0dp"
            android:layout_height="Wrap_content"
            android:layout_weight="1">
</LinearLayout>

这是我会怎么做。我假设你想你的widget占用一半,而另一小部件占用的另一半。诀窍是使用的LinearLayout,两个小部件设置 layout_width =FILL_PARENT layout_weight 设置为相同的值在两个部件为好。如果有两个窗口小部件,都具有相同的重量,所述的LinearLayout会分割两个小部件之间的宽度。

This is how I'd do it. I'm assuming you want your widget to take up one half, and another widget to take up the other half. The trick is using a LinearLayout, setting layout_width="fill_parent" on both widgets, and setting layout_weight to the same value on both widgets as well. If there are two widgets, both with the same weight, the LinearLayout will split the width between the two widgets.

这篇关于指定宽度的一半可用屏幕宽度声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆