我的 ListView 使用以下项目布局。我期望第二个 TextView(txt_time) 出现在第一个 TextView(txt_chat) 的下方和右侧。但两者都出现在彼此相邻的同一垂直空间上。我尝试向第一个 TextView 添加底部填充,但它使第二个 TextView 也自动向上移动以与第一个 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="wrap_content">
<LinearLayout
android:id ="@+id/wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bubble_green"
android:orientation="horizontal">
<TextView
android:id="@+id/txt_chat"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:focusable="false"
android:paddingBottom="20px"
/>
<TextView
android:id="@+id/txt_time"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="test"
android:paddingBottom="0px"
/>
</LinearLayout>
</LinearLayout>
这就是我想要实现的目标:
最佳答案
使用使用dp或dip
,而不是px
进行填充。并将以下 View 替换为现有 View ..
<TextView
android:id="@+id/txt_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="top"
android:layout_gravity="top"
android:paddingBottom="20dip" />
<TextView
android:id="@+id/txt_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_gravity="bottom"
android:text="test" />
关于android - TextView 的填充应用于线性布局中的其他 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24114437/