2015-03-21 4 views
0

Мое приложение извлекает данные пользователя из БД и отображает их в ListView. Однако содержимое, отображаемое в ListView, не отформатировано должным образом.Содержание в ListView не сосредоточено

Это как мой макет в настоящее время оказывается: enter image description here

Это мой файл макета для деятельности:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    android:paddingBottom="16dp" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:paddingTop="16dp" 
    tools:context=".LeaderBoard" > 

    <LinearLayout 
     android:id="@+id/column" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/column_header1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" 
      android:text="@string/strLBoardHeaderRank" 
      android:textColor="#f00" 
      android:textSize="24sp" /> 

     <TextView 
      android:id="@+id/column_header2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.6" 
      android:text="@string/strLBoardHeaderName" 
      android:layout_gravity="center" 
      android:textColor="#f00" 
      android:textSize="24sp" /> 

     <TextView 
      android:id="@+id/column_header3" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" 
      android:text="@string/strLBoardHeaderScore" 
      android:textColor="#f00" 
      android:textSize="24sp" /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/column" > 
    </ListView> 

</RelativeLayout> 

Файл макета для списка активности ниже:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" > 

    <TextView 
     android:id="@+id/rank" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.2" 
     android:textColor="#f00" 
     android:textSize="20sp" /> 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.6" 
     android:textColor="#f00" 
     android:textSize="20sp" /> 

    <TextView 
     android:id="@+id/score" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.2" 
     android:textColor="#f00" 
     android:textSize="20sp" /> 

</LinearLayout> 

ответ

1

добавить android:gravity="center" для всех textview s и файл макета для списка деятельности textview s ширина должен быть 0dp из-за веса собственности и у следует также добавить android:orientation="horizontal"

<TextView 
      android:id="@+id/column_header1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" 
      android:gravity="center" 
      android:text="strLBoardHeaderRank" 
      android:textColor="#f00" 
      android:textSize="24sp" /> 

     <TextView 
      android:id="@+id/column_header2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.6" 
      android:gravity="center" 
      android:text="strLBoardHeaderName" 
      android:layout_gravity="center" 
      android:textColor="#f00" 
      android:textSize="24sp" /> 

     <TextView 
      android:id="@+id/column_header3" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" 
      android:gravity="center" 
      android:text="strLBoardHeaderScore" 
      android:textColor="#f00" 
      android:textSize="24sp" /> 

макет файла для списка

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/rank" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.2" 
     android:gravity="center" 
     android:textColor="#f00" 
     android:textSize="20sp" /> 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.6" 
     android:gravity="center" 
     android:textColor="#f00" 
     android:textSize="20sp" /> 

    <TextView 
     android:id="@+id/score" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.2" 
     android:gravity="center" 
     android:textColor="#f00" 
     android:textSize="20sp" /> 

</LinearLayout> 
+0

Спасибо. Это сработало. – webgenius

+0

u приветствую ... :) –

0

Попробуйте это, это работает для меня

//Main Layout 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    android:orientation="horizontal" > 
<TableLayout 
        android:id="@+id/add_rule_table" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_margin="2dp" 
        android:layout_marginTop="5dp" 
        android:background="@color/list_divider" 
        android:orientation="vertical" 
        android:stretchColumns="*" 
        android:visibility="gone" > 

        <TableRow 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:background="@color/list_divider" 
         android:orientation="horizontal" > 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:background="@color/list_divider" 
          android:ems="4" 
          android:gravity="center" 
          android:text="@string/rule_no" 
          android:textSize="12sp" 
          android:textStyle="bold" /> 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:background="@color/list_divider" 
          android:ems="4" 
          android:gravity="center" 
          android:text="@string/lot" 
          android:textSize="12sp" 
          android:textStyle="bold" /> 

         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:background="@color/list_divider" 
          android:ems="4" 
          android:gravity="center" 
          android:text="@string/discount" 
          android:textSize="12sp" 
          android:textStyle="bold" /> 


        </TableRow> 

        <View 
         android:layout_width="fill_parent" 
         android:layout_height="1dp" 
         android:background="@color/list_divider" /> 
       </TableLayout> 


        <ListView 
         android:id="@+id/rule_list_view" 
         android:layout_width="0dip" 
         android:layout_height="wrap_content" 
         android:layout_marginBottom="2dp" 
         android:layout_weight="1" 
         android:background="@android:color/transparent" 
         android:cacheColorHint="#00000000" 
         android:choiceMode="none" 
         android:listSelector="@android:color/transparent" /> 

      </LinearLayout> 


//Custom List View Items 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff" 
    > 

    <TableLayout 
     android:id="@+id/add_rule_table" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="2dp" 
     android:layout_marginTop="5dp" 
     android:background="@color/white" 
     android:orientation="vertical" 
     android:stretchColumns="*" > 

     <TableRow 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/white" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/rule_nos" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left|center_vertical" 
       android:layout_marginRight="1dp" 
       android:ems="3" 
       android:gravity="center_horizontal" 
       android:paddingBottom="5dp" 
       android:paddingTop="5dp" 
       android:text="1" 
       android:textSize="12sp" /> 

      <TextView 
       android:id="@+id/lots" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:ems="4" 
       android:gravity="center" 
       android:paddingBottom="5dp" 
       android:paddingTop="5dp" 
       android:text="23" 
       android:textSize="12sp" /> 

      <TextView 
       android:id="@+id/discount" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:ems="4" 
       android:gravity="center" 
       android:paddingBottom="5dp" 
       android:paddingTop="5dp" 
       android:text="34%" 
       android:textSize="12sp" /> 

      <TextView 
       android:id="@+id/edit_rule" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/edit_rule" 
       android:ems="4" 
       android:gravity="center_horizontal" 
       android:text="@string/edit" 
       android:textColor="#ffffff" 
       android:textSize="12sp" /> 

      <TextView 
       android:id="@+id/delete_rule" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right|center_vertical" 
       android:background="@drawable/delete_rule" 
       android:ems="4" 
       android:gravity="center_horizontal" 
       android:text="@string/delete" 
       android:textColor="#ffffff" 
       android:textSize="12sp" /> 
     </TableRow> 
    </TableLayout> 

</LinearLayout> 
Смежные вопросы