2016-08-24 3 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> 

EDIT

Текущий выпуск он показывает что-то вроде

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

Но что я хочу

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

Я попробовал версию @Priyank Prajapati, но она до дает прежнее расположение

+0

Add Static ширина –

+0

для всех изменений TextViews 'андроида: 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

, пожалуйста, проверьте мой отредактированный ответ, если вы хотите изменить гравитацию, а затем используйте андроид: 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" для каждого будет unifrom его для всех строк

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

проверить обновленный ответ я изменил код. –