android - 在同一行的 textView 旁边添加 ImageView

标签 android xml android-xml

我在 CardView 中有一个 TextView 和一个 ImageView。
我有一个关于 TextView 的问题。
当 TextView 文本长于 CardView 长度时,它会显示在 ImageView 上,我不希望这样。

喜欢这张照片:

enter image description here

我想要它,以便当文本接触到 ImageIiew 时,它会显示 ... 以指示文本继续。

row.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:layout_margin="4dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/txt_file_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"/>

        <ImageView
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:src="@drawable/ic_delete_forever_red_500_24dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"/>

    </RelativeLayout>
</android.support.v7.widget.CardView>

这是我想要的屏幕截图:

enter image description here

最佳答案

试试下面的代码。希望有用

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:layout_margin="4dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/txt_file_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/imageView"
            android:layout_marginLeft="16dp"
            android:layout_centerVertical="true"/>

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:src="@drawable/ic_delete_forever_red_500_24dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"/>


    </RelativeLayout>
</android.support.v7.widget.CardView>

关于android - 在同一行的 textView 旁边添加 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37507337/

相关文章:

Android:GridView auto_fit 如何查找列数?

Android:不同语言的 "String Array",输入 "Assets"还是 "strings.xml"?

android - 为蜂窝前的两层可绘制项目设置动画

android - 如何从 android 中的数据库 SQlite 中删除前 10 行?

android - 使用 HockeyApp SDK 自动更新应用程序

android - SwipeRefreshLayout 内的 NestedScrollView 内的 RecyclerView 滚动不流畅

java - 如何解决 android studio 中的错误 'Package R doesn' t exit' 和 'Execution failed for task":app.compileDebugJavaWithJavac"' 错误?

java - 如何提高拆分 xml 文件的性能

java - 在 Jenkins 文件夹中的任何地方都找不到 config.xml

Android XML 有没有办法将工具命名空间与自定义属性一起使用?