Android是什么:weightSum在Android中,它是如何工作的? [英] What is android:weightSum in android, and how does it work?

查看:430
本文介绍了Android是什么:weightSum在Android中,它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道:什么是机器人:weightSum和布局的重量,以及他们是如何工作的。

I want to know: What is android:weightSum and layout weight, and how do they work?

推荐答案

最好是用一个例子来解释。

It is better to explain with an example.

您有一个的LinearLayout 与水平方向,你有3 ImageViews 里面,你想这些 ImageViews 总是采取平等的空间。

You have a LinearLayout with horizontal orientation and you have 3 ImageViews inside it and you want these ImageViews always to take equal space.

  <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:weightSum="3"
    android:orientation="horizontal"
    android:layout_gravity="center">

您可以设置 layout_weight 每个的ImageView 1和 weightSum 的LinearLayout 3实现这一目标。

You can set the layout_weight of each ImageView to 1 and the weightSum in LinearLayout to 3 to achieve this.

<ImageView
    android:layout_height="wrap_content"       
    android:layout_weight="1"
    android:layout_width="0dp"/>

好一点的是,这将正常工作的任何设备,如果你直接设置宽度和高度,这将不会发生。

The good point is that this will work correctly for any device, which will not happen if you set width and height directly.

这篇关于Android是什么:weightSum在Android中,它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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