2015-09-30 59 views
0

我跟進了android docs,在我的應用主要活動上構建了導航抽屜。但內容是在我的主要活動java代碼中的字符串數組中。列表視圖元素不排隊。 enter image description hereAndroid導航抽屜中的ListView內容不排隊

如何讓它們排列在左邊,使它們都與屏幕左側的距離相等?我也希望在縱向和佈局模式下這種行爲。 這是我的xml文件。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <fragment 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" /> 

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

     <TextView 
      android:id="@+id/tvan" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:textColor="@color/blue" 
      android:textSize="@dimen/abc_action_bar_default_height_material" 
      android:text="@string/app_name" /> 

     <AutoCompleteTextView 
      android:id="@+id/acgetd" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:gravity="center_horizontal" /> 

     <requestFocus /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:layout_gravity="bottom" > 

      <Button 
       android:id="@+id/bgetd" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:background="@drawable/skimmy" 
       android:text="@string/bgetd" /> 

      <Button 
       android:id="@+id/brejec" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:background="@drawable/skimmy" 
       android:text="@string/reject" /> 
     </LinearLayout> 
    </LinearLayout> 
</FrameLayout> 
    <ListView 
     android:id="@+id/MList" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="left" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:background="#111"> 
    </ListView> 
</android.support.v4.widget.DrawerLayout> 

回答

1

從您分享的鏈接中,可以看到佈局R.layout.drawer_list_item。有一個名爲drawer_list_item.xml的XML佈局。這是負責listView中所有項目的文件。 檢查gravity在XML和刪除或屬性設置爲alignParentLeft

0

你可以發佈活動和列表視圖項目的xml文件嗎?

我懷疑你是在List的TextView中使用android:gravity =「center」而不是android:gravity =「center_vertical」。

對不起,發佈這個答案。我沒有50個代表發表評論。

0

我覺得你的ListView的文字對齊到中心,

android:layout_gravity="center 

更改,向左或向右根據您的要求
這可能有助於