2014-07-26 25 views
0

我有我的列表中該佈局的每個項目:爲什麼我的TextView在每個列表項中都有不同的位置?

<?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="match_parent" 
    android:orientation="vertical" 
    android:paddingLeft="8dp" 
    android:paddingRight="8dp" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="360dp" 
     android:orientation="horizontal" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" > 

     <ImageView 
      android:id="@+id/offerImage" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:src="@drawable/lock_closed" /> 

     <TextView 
      android:id="@+id/offerText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/imageButton1" 
      android:layout_alignParentRight="true" 
      android:layout_marginBottom="84dp" 
      android:text="ad text here!" /> 

     <ImageButton 
      android:id="@+id/lockImage" 
      android:layout_width="60dp" 
      android:layout_height="60dp" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:layout_marginBottom="82dp" 
      android:scaleType="fitXY" 
      android:src="@drawable/lock_closed" /> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignRight="@+id/offerImage" 
      android:layout_alignTop="@+id/lockImage" 
      android:layout_marginRight="44dp" 
      android:text="TextView" 
      android:textColor="#FFFFFF" /> 

     <TextView 
      android:id="@+id/address" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/textView2" 
      android:layout_alignLeft="@+id/textView2" 
      android:text="TextView" 
      android:textColor="#FFFFFF" /> 

     <com.example.customViews.AngledTextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/offerImage" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="35dp" 
      android:layout_marginTop="84dp" 
      android:text="Large Text" /> 
    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:orientation="horizontal" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" > 

     <Button 
      android:id="@+id/saveBtn" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="#0db7ff" 
      android:text="@string/save" /> 

     <View 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" /> 

     <Button 
      android:id="@+id/likeBtn" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="#0db7ff" 
      android:text="@string/like" /> 

     <View 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" /> 

     <Button 
      android:id="@+id/unlikeBtn" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="#0db7ff" 
      android:text="@string/unlike" /> 
    </LinearLayout> 

</LinearLayout> 

當我看着我的列表我看到在不同的地方文本視圖。怎麼來的?

enter image description here

enter image description here

此外,我已經實現了沉默呼叫我的名單。

有時候列表循環時間太長而用戶看到的照片替換

(意爲老項目的照片被替換爲新項目的照片)。

我該如何使它更加無縫?

回答

2

您已將它對齊到鎖定圖像的頂部。如果鎖定圖像不在您的視圖中,則它將不會被正確錨定,並且會出現在稍微奇怪的地方。注意失敗案例沒有鎖定圖像。解決方案是將其錨定到y方向的其他位置,所以不會在沒有鎖定圖像的情況下懸浮。另一種可能性是當鎖定圖像未顯示時將鎖定圖像設置爲INVISIBLE而不是GONE,因此它仍然爲它保留空間,並且文本視圖與它存在的位置對齊。

+0

謝謝。我的第二個問題怎麼樣:有時回收清單太長,用戶看到更換照片 (意思是舊的項目照片被替換爲新的項目照片)。 我怎樣才能讓它更加無縫? –

-1

1)從未固定(以得到像35dp靜態值)的任何圖像,佈局的高度和寬度PARAM,按鈕

2.)爲了使有效的廣告應用程式:下面是列表應用程序中的資源目錄,爲不同的屏幕尺寸提供不同的佈局設計,併爲中等,高和超高密度屏幕提供不同的位圖可繪製。

更多詳情Read this article

res/layout/my_layout.xml    // layout for normal screen size ("default") 
res/layout-small/my_layout.xml  // layout for small screen size 
res/layout-large/my_layout.xml  // layout for large screen size 
res/layout-xlarge/my_layout.xml  // layout for extra large screen size 
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation 

res/drawable-mdpi/my_icon.png  // bitmap for medium density 
res/drawable-hdpi/my_icon.png  // bitmap for high density 
res/drawable-xhdpi/my_icon.png  // bitmap for extra high density 
+1

這是非常有用的信息。但我不知道它是如何與我的2個問題相關的 –

+0

我想告訴你,你已經給android:layout_height =「360dp」 不是佈局設計的好習慣。 –

+0

儘量遵循鏈接中給出的所有規則,並且您將解決所有問題。 –

相關問題