2016-08-24 70 views
-6

现在每行的宽度根据文本的大小而变化。但是我希望每个列都有固定的大小,比如excel。应该改变什么?它不应该被match_parent因为家长有非常大的宽度..如何修复色谱柱宽度?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

    <TextView 
      android:id="@+id/name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:textAppearance="?attr/textAppearanceListItem" /> 

    <TextView 
      android:id="@+id/email" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:textAppearance="?attr/textAppearanceListItem" /> 

    <TextView 
     android:id="@+id/short_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/text_margin" 
     android:textAppearance="?attr/textAppearanceListItem" /> 
</LinearLayout> 

编辑

当前版本它表明类似

Chris [email protected] R 
Apostole [email protected] - 

但我要的是

Chris [email protected] R 
Apostole [email protected] - 

我试过@Priyank Prajapati的版本,但它s直到给前者布局

+0

添加静态宽度 –

+0

所有textviews变化'的android:layout_width = match_parent'并添加'机器人:体重= 1' –

+1

变化'layout_width = “0dp”'和'添加layout_weight = “1”'; –

回答

1

做这样的事情:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

    <TextView 
      android:id="@+id/name" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:textAppearance="?attr/textAppearanceListItem" /> 

    <TextView 
      android:id="@+id/email" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:textAppearance="?attr/textAppearanceListItem" /> 

    <TextView 
     android:id="@+id/short_name" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/text_margin" 
     android:textAppearance="?attr/textAppearanceListItem" /> 
</LinearLayout> 
+0

感谢您的回答。请参阅编辑。 – Student

+1

请检查我编辑的答案,如果你想改变重力,然后使用android:gravity =“center”或android:gravity =“right”如果有任何查询让我知道,试试这个。 –

1

更改父android:layout_width="wrap_content"android:layout_width="match_parent"

注:使用android:layout_weight="1"with android:layout_width="0dp"每个将高校统战它的所有行

enter image description here

全码:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="10"> 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/activity_horizontal_margin" 
     android:layout_weight="2" 
     android:text="Chris" 
     android:textAppearance="?attr/textAppearanceListItem" /> 

    <TextView 
     android:id="@+id/email" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/activity_horizontal_margin" 
     android:layout_weight="8" 
     android:text="[email protected]" 
     android:textAppearance="?attr/textAppearanceListItem" /> 

    <TextView 
     android:id="@+id/short_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/activity_horizontal_margin" 
     android:layout_weight="1" 
     android:text="R" 
     android:textAppearance="?attr/textAppearanceListItem" /> 
</LinearLayout> 
+0

尝试我的代码将产生相同的结果 –

+0

检查更新的答案我已修改代码。 –