2017-06-01 94 views
0

我做了一個自定義adapterlistview但它不工作,兩個textview覆蓋當我建立,但它工作時,我做的xml,我用layout_below
enter image description herelayout_below在自定義適配器在列表視圖

字符串 「阮國保」 和 「13530」 是覆蓋
在XML
enter image description here

xml代碼:

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

    <TextView 
     android:id="@+id/textView_stud_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     android:paddingLeft="8dp" 
     android:textSize="18sp" 
     android:textStyle="bold" 
     android:text="111"/> 

    <TextView 
     android:id="@+id/textView_stud_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_below="@+id/textView_stud_name" 
     android:paddingLeft="8dp" 
     android:textSize="12sp" 
     android:text="111"/> 

    <Button 
     android:id="@+id/btn_absence" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="5dp" 
     android:background="@color/red" 
     android:text="Absence" /> 

    <Button 
     android:id="@+id/btn_check" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/btn_absence" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="5dp" 
     android:background="@color/green" 
     android:text="Check" /> 

</RelativeLayout> 

如何解決這個問題?感謝您的迴應。

回答

1

,因爲它是粘貼此佈局,這種設計給你更多的靈活性,爲未來變化(尖 - 嘗試使用線性佈局儘可能您也可以因爲相對佈局可能會改變他的行爲太在運行時)

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

     <LinearLayout 
      android:layout_alignParentLeft="true" 
      android:layout_width="match_parent" 
      android:orientation="vertical" 
      android:layout_toLeftOf="@+id/llButtons" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/textView_stud_name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" 
       android:paddingLeft="8dp" 
       android:text="111" 
       android:textSize="18sp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/textView_stud_id" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/textView_stud_name" 
       android:layout_centerVertical="true" 
       android:paddingLeft="8dp" 
       android:text="111" 
       android:textSize="12sp" /> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/llButtons" 
      android:layout_alignParentRight="true" 
      android:layout_width="wrap_content" 
      android:orientation="horizontal" 
      android:layout_height="wrap_content"> 
      <Button 
       android:id="@+id/btn_absence" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:textColor="@color/black" 
       android:layout_marginRight="5dp" 
       android:background="@color/red" 
       android:text="Absence" /> 

      <Button 
       android:id="@+id/btn_check" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_marginRight="5dp" 
       android:layout_toLeftOf="@id/btn_absence" 
       android:background="@color/green" 
       android:text="Check" /> 

     </LinearLayout> 


    </RelativeLayout> 
+0

感謝您的幫助,但如果我想繼續我的第一種方式,該如何解決? –

+0

你必須保持太多的觀點關係......就像這個觀點在這個觀點左邊,這個觀點正好在這個下面,在這個......之上......更忙碌而沒有維護他的形狀 –

0

刪除layout_centerVertical屬性從第二個TextView

如果爲true,則將此孩子垂直居中在其父代中。

<TextView 
     android:id="@+id/textView_stud_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     android:paddingLeft="8dp" 
     android:textSize="18sp" 
     android:textStyle="bold" 
     android:text="111"/> 

     <TextView 
      android:id="@+id/textView_stud_id" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textView_stud_name" 
      android:paddingLeft="8dp" 
      android:textSize="12sp" 
      android:text="111"/> 
+0

它移動到下方,但仍重疊,我想是因爲邊距/填充 –

+1

@HoàngĐăng更好的方式,使用的LinearLayout和添加'安卓layout_weight' –

+0

@HoàngĐăng如果你將面對的問題讓我通知。 –

相關問題