Android 当屏幕宽度较小时,如何在右对齐按钮旁边省略号居中对齐的文本视图 ------------------------------------ |长标题|按钮|| |------------------------------------| | |
我有一个应用标题,其中包括应用标题和一个按钮。按钮应该固定在右侧,但是当屏幕太小的时候,我希望标题是中间的和椭圆形的。问题是标题不会省略,即使按钮就在旁边 以下是我目前掌握的情况:Android 当屏幕宽度较小时,如何在右对齐按钮旁边省略号居中对齐的文本视图 ------------------------------------ |长标题|按钮|| |------------------------------------| | |,android,android-layout,Android,Android Layout,我有一个应用标题,其中包括应用标题和一个按钮。按钮应该固定在右侧,但是当屏幕太小的时候,我希望标题是中间的和椭圆形的。问题是标题不会省略,即使按钮就在旁边 以下是我目前掌握的情况: 有没有一种方法可以通过使用RelativeLayout实现这一点? ------------------------------------ | LONG_TITL... |button| | |------------------------------------| |
有没有一种方法可以通过使用RelativeLayout实现这一点?
------------------------------------
| LONG_TITL... |button| |
|------------------------------------|
| |
在TextView中更改为android:ellipsize=“end”。将此添加到您的TextView中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toLeftOf="@+id/button"
android:ellipsize="end"
android:singleLine="true"
android:text="very large center align text very large center align text very large center align text" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Right button" />
</RelativeLayout>
</RelativeLayout>
设置文本视图的固定宽度android如何:ellipsize=“end”我也尝试过这个方法和其他可能的值,但都不起作用。我尝试增加按钮的左边距,但标题不会移动..请检查下面的答案问题是标题不在中间。如果标题左侧没有视图,则它将占据中心所需的空间。如果仍然无法显示某些文本,然后它将应用省略号属性。如果你想让你的标题准确地位于中心,而不考虑其他视图,那么你必须对标题所在的所有视图使用权重。嗯。。但是如果我必须使用权重,那么我就不应该使用
LinearLayout
,对吗?或者如果我只是在左边添加一个不可见的视图会更好?你最好使用LinearLayouterr是的。对不起,应该是“.那么我应该使用LinearLayout
…”
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"