Joh*_*son 3 android android-layout
我想在同一行上有两个 textView。下面你可以看到我的String对象长和短时的交互作用。
我正在尝试在 android xml 视图中执行此操作。
(当第一个文本很短时,第二个文本必须留在第一个文本的右侧)
这是我的代码:
<LinearLayout
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:gravity="start|center_vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:paddingRight="40dp"
android:scrollHorizontally="true"
android:text="TextView long"
android:textColor="@android:color/white"
android:textSize="15sp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:maxLines="1"
android:text="Text"
android:textColor="@android:color/white"
android:textSize="15sp" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的问题是我的第二个文本“文本”每次都保留在正确的父级上......
使用 tablelayout 并将两个文本框放在表格行中尝试。检查此代码。
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:layout_margin="10dp"
android:background="@android:color/white"
android:shrinkColumns="0"
>
<TableRow>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView toooooooooooooooooooooooooooooooooooo long"
android:layout_marginLeft="10dp"
android:ellipsize="end"
android:singleLine="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview"
android:gravity="start"
android:textColor="@android:color/black"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:ellipsize="none"
android:singleLine="true"
/>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
531 次 |
| 最近记录: |