我的列表中的每个项目都有这样的布局:
<?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>
当我查看列表时,我在不同的位置看到 TextView 。怎么会这样?
此外,我还为我的列表实现了静默寻呼。
有时列表回收时间太长,用户会看到照片替换
(意味着旧的商品照片被新的商品照片替换)。
如何才能使其更加无缝?
最佳答案
您已将其与锁定图像的顶部对齐。如果锁定图像不在您的 View 中,则它不会正确锚定,并且会出现在稍微奇怪的位置。请注意,失败案例没有锁定图像。解决方案是将其锚定到 y 方向上的其他位置,这样它就不会在没有锁定图像的情况下 float 。另一种可能性是在未显示时将锁定图像设置为“不可见”而不是“消失”,因此它仍然有为其保留的空间,并且 TextView 与它存在时的位置对齐。
关于java - 为什么我的 TextView 在每个列表项中的位置不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24969723/