作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
------------------------------------| LONG_TITL... |button| ||------------------------------------|| |
I have an app header which consists of the app title and a button. The button should be fixed on the right side but I want the title to be in the middle and ellipsize when the screen is too small. Problem is the title just won't ellipsize even though the button is nearly beside it.
Here's what I have so far:
<RelativeLayout android:id="@+id/headr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/bar_orange"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:minHeight="40dp"
android:scaleType="centerCrop"
android:src="@drawable/bar_orange"/>
<TextView
android:id="@+id/Title"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="@string/bcd"
android:textColor="#FFFFFF"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="18sp"
android:textStyle="bold"/>
<Button
android:padding="5dp"
android:id="@+id/home"
android:textColor="#ffffff"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:singleLine="true"
android:background="@drawable/button_home"
android:text="@string/home"/>
</RelativeLayout>
有没有办法只用 RelativeLayout
来做到这一点?
最佳答案
<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 - 当屏幕宽度较小时,如何在右对齐按钮旁边省略居中对齐的 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17356705/
我是一名优秀的程序员,十分优秀!