设置宽度TextView中的一个的LinearLayout [英] Setting width of textview in a LinearLayout

查看:85
本文介绍了设置宽度TextView中的一个的LinearLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个列表视图的标题。 ListView的头有三列。假设A,B,C。我用两个LinearLayouts设计的ListView头,如下所示:

I am using a header for a Listview. ListView header has three columns. Say a,b,c. I am using two LinearLayouts to design ListView header as shown below:

<?xml version="1.0" encoding="utf-8"?>   
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
 android:layout_width="fill_parent"  
 android:layout_height="40dip"  
 android:padding="0dip">  
 <LinearLayout  
    android:orientation="horizontal"  
    android:background="#1e90ff"  
    android:layout_width="0dip"  
    android:layout_weight="1"  
    android:padding="5dip"  
    android:layout_height="40dip">  
    <TextView  
        android:id="@+id/a"  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent"  
        android:textColor="#000000"  
        android:layout_weight="1"  
        android:gravity="center_vertical"  
        android:text="@string/a"  
    />  
    <TextView  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent"  
        android:textColor="#000000"  
        android:layout_weight="1"  
        android:gravity="center_vertical"  
        android:id="@+id/b"  
        android:singleLine="true"  
        android:text="@string/b"  
    />  
    <TextView  
        android:layout_width="fill_parent"   
        android:layout_height="fill_parent"  
        android:textColor="#000000"  
        android:layout_weight="1"  
        android:gravity="center_vertical"  
        android:id="@+id/c"  
        android:singleLine="true"  
        android:text="@string/c"  
    />  
 </LinearLayout>   
</LinearLayout>

现在我要修复列的宽度,B,C分别。如何设置宽度这些列?再次,是它使用的LinearLayout这一个好的做法呢?请指教。

Now i want to fix the width of columns a, b, c respectively. How to set width of these columns ? Again, is it a good practise to use LinearLayout for this ? Please Advise.

推荐答案

要更改textviews的layout_width为固定宽度的使用:

To change the layout_width of your textviews to a fixed width use:

 android:layout_width="40dip"

或者,你希望他们占用屏幕的比例改变layout_weight

Or of you want them to take up percentages of the screen change the layout_weight

 android:layout_weight="2"

在中另一个的android所有元素的重量(如这里的线性布局)将被添加在一起,然后用每个视图的重量来定义多少空间需要。 I.E.如果你有作为的权重为2,3,5,A,B,c分别,那么将是20%宽,B 30%,宽C 50%宽。

In android the weight of all elements within another one (such as your linear layout here) will be added together and then using the weight of each view to define how much space it takes. I.E. if you had the weights as 2,3,5 for a,b,c respectively, then a would be 20% wide, b 30% wide and c 50% wide.

如果你想列时,应考虑使用表格布局(教程

If you want columns, you should consider using a table layout (tutorial)

这篇关于设置宽度TextView中的一个的LinearLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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