我有这个布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:azeoo="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/opening_today_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<TextView
android:id="@+id/opening_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="A standard line" />
<ImageView
android:layout_toRightOf="@id/opening_today"
android:layout_width="32dp"
android:layout_height="32dp"
android:paddingLeft="8dp"
android:src="@drawable/ic_arrow_drop_down" />
</RelativeLayout>
</LinearLayout>
结果是:
但是,如果我为“opening_today”添加一个长文本,例如“非常非常非常长的行,并且有许多带有ellipsize end的文本”,ImageView就会消失:
那么,即使文字尺寸很大,我怎样才能保持 ImageView?
答案 0 :(得分:2)
尝试这可能对您有所帮助
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:azeoo="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/opening_today_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<TextView
android:id="@+id/opening_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:layout_toLeftOf="@+id/iv"
android:maxLines="1"
android:text="A very very very long line with a lot of texts with ellipsize end" />
<ImageView
android:id="@+id/iv"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:paddingLeft="8dp"
android:src="@drawable/ic_arrow_drop_down" />
</RelativeLayout>
答案 1 :(得分:0)
试试这个
<RelativeLayout
android:id="@+id/opening_today_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
>
<TextView
android:id="@+id/opening_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="A standard lffsdfsfsdfsfsfhgf fkhh gkjhg hkgj jhg hjgk jhg jkgjhg kjh jhgkj gkjsfsfsdfsdfsfsfdfdfdfsdf sdfsdfsdf sdfsdfsdfsdfsfdsdfsdfsfsfine"
android:drawableRight="@drawable/ic_arrow_drop_down"
/>
</RelativeLayout>
答案 2 :(得分:0)
正如 cricket_007 在评论中所说,您可以使用TextView
android:drawableRight
代码中引用图片direclty
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:azeoo="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/opening_today_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<TextView
android:id="@+id/opening_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="A standard line A standard line A standard line A standard line A standard line"
android:drawableRight="@drawable/ic_arrow_drop_down"/>
</RelativeLayout>
执行此操作后,您无法再像初始代码那样指定图像的高度和宽度。请务必在所有res/drawable
文件夹中保留正确的图片大小。