我希望两个TextView元素并排显示(在列表项中),一个元素向左对齐,一个向右对齐.就像是:
|<TextView> <TextView>|
Run Code Online (Sandbox Code Playgroud)
(|代表屏幕的四肢)
但是,TextView左侧的内容可能太长而无法放在屏幕上.在这种情况下,我想让它椭圆形但仍然显示完整的权利TextView.就像是:
|This is a lot of conte...<TextView>|
Run Code Online (Sandbox Code Playgroud)
我在此进行过多次尝试,同时使用LinearLayout和RelativeLayout,和我想出了唯一的解决办法是使用RelativeLayout,把一个marginRight在左边TextView足够大的权明确TextView.但是,你可以想象,这不是最佳选择.
还有其他解决方案吗?
最终LinearLayout解决方案:
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:inputType="text"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="0"
android:layout_gravity="right"
android:inputType="text"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
旧的,TableLayout解决方案:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:shrinkColumns="0"
>
<TableRow>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
/>
<TextView android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="none" …Run Code Online (Sandbox Code Playgroud) 我对TextView有一个奇怪的问题,它在最后切断了部分文本.我的布局看起来像
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|center_horizontal"
android:gravity="top|center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|center_horizontal"
android:gravity="top|center_horizontal"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_marginBottom="5dp">
<Button
android:id="@+id/btnPreviousQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_arrow_left"
android:clickable="true"
android:visibility="gone" >
</Button>
<TextView
android:id="@+id/txtQuestion"
style="@style/question_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top|center_horizontal"
android:layout_weight="1"
/>
<Button
android:id="@+id/btnNextQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="@drawable/selector_arrow_right"
android:clickable="true" >
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="horizontal" >
<WebView
android:id="@+id/wvMultimediaQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginLeft="50dp"
android:layout_marginRight="55dp"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
和txtQuestion在文本足够长时切断文本.有什么不对,有人知道吗?
第一次在这个论坛发帖,希望一切顺利:)
我正在为我所在城市的公共交通开发 Android 应用程序。
[ |short destination ||next departure| ]
[ |way too long dest...||next departure| ]
Run Code Online (Sandbox Code Playgroud)
[ |short destination||next departure| ]
[ |way too long dest...||next departure| ]
Run Code Online (Sandbox Code Playgroud)
这是一个更完整的示例:s28.postimg.org/5gejnvfd9/actual2.png
奇怪的彩色背景只是为了轻松识别布局/文本视图。您也可以忽略棕色线(没关系)。
基本上,我想要具有可变长度的目的地[红色背景],在其右侧,我想要第一个出发时间[绿色背景]。一切都在一条线上。
我需要始终完整显示第一个出发信息(nowrap)。目的地可以用省略号 (...) 括起来。[可选问题,如何将省略号“...”替换为“.” ?]
这是迄今为止我拥有的最好的工作代码:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtTitleDestination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/txtTitleFirstDeparture"
android:background="#FF0000"
android:ellipsize="end"
android:maxLines="1"
android:padding="0dp"
android:scrollHorizontally="true"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtTitleFirstDeparture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_alignParentRight="true"
android:background="#00FF00"
android:ellipsize="none"
android:maxLines="1"
android:padding="0dp"
android:textSize="18sp"
android:textStyle="bold"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我尝试过 TableLayout 和 LinearLayour 而不是relativelayout,但没有成功:(
知道我该怎么做吗?
提前致谢!
卢卢克斯
[已解决] …