线性布局和重量在Android的 [英] Linear Layout and weight in Android

查看:207
本文介绍了线性布局和重量在Android的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是读到在Android单证这个有趣的权重值。 现在,我想尝试的第一次,但它是不工作的。

I always read about this funny weight value in the Android documentations. Now I want to try it for the first time but it isn't working at all.

据我所知,从单证此布局:

As I understand it from the documentations this layout:

  <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal">

     <Button
        android:text="Register"
        android:id="@+id/register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dip"
        weight="1" />

     <Button
        android:text="Not this time"
        android:id="@+id/cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dip"
        weight="1" />

  </LinearLayout>

应该创建两个按钮,水平排列,并平均分配的空间。问题是两个按钮不生长,以填补空间。

should create two buttons that are horizontally aligned and share the space equally. The problem is the two buttons don't grow to fill the space.

我想的按钮增长,填补了整条生产线。如果两个按钮都设置为匹配父只显示第一个按钮,并填满整个行。

I would like the buttons to grow and fill the whole line. If both buttons are set to match parent only the first button is shown and fills the whole line.

推荐答案

我想我找到了问题。你是不是设置了 layout_weight 属性。您的code读重=1,它应该读的android:layout_weight =1

I think I found the problem. You are not setting the layout_weight property. Your code reads weight="1" and it should read android:layout_weight="1".

这篇关于线性布局和重量在Android的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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