0dip layout_height 或 layouth_width 有什么技巧? [英] What is the trick with 0dip layout_height or layouth_width?

查看:19
本文介绍了0dip layout_height 或 layouth_width 有什么技巧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是为什么有人希望他们看到 0dip 高度?这个我见过很多次了,一定有什么套路,但我不明白.

I mean why anybody want they view to be 0dip height ? I have seen this many times, there must be some kind of trick, but I do not get it.

        <TextView android:gravity="top" android:textColor="#FFFF0000"
            android:textSize="20dip" android:text="TextView"
            android:layout_height="0dip" android:layout_width="fill_parent"
            android:id="@+id/contactName"></TextView>

为什么他们不使用例如 wrap_content ?他们想达到什么目的?

Why they don't use for example wrap_content ? what do they want to achieve ?

推荐答案

这通常用于在一个线性布局中有多个视图并且设置了 android:layout_weight="1" 以使两个视图占据相等空间的情况.例如:

This is usually used when having many views inside a linearlayout and have set android:layout_weight="1" in order both views to take equal space. for example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="TextView" />

</LinearLayout>

在这种情况下,视图将占用与所有其他视图一样多的高度.

In that case, the view will take as much height as all other views.

这篇关于0dip layout_height 或 layouth_width 有什么技巧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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