Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在同一行的textView旁边添加ImageView_Android_Xml_Android Xml - Fatal编程技术网

Android 在同一行的textView旁边添加ImageView

Android 在同一行的textView旁边添加ImageView,android,xml,android-xml,Android,Xml,Android Xml,我在CardView中有一个文本视图和一个图像视图。 我对文本视图有一个问题。 当TextView文本长于CardView长度时,它会显示在ImageView上,我不希望这样 就像这张照片: 我希望这样,当文本接触到ImageIiew时,它会显示…,以指示文本继续 row.xml 您可以利用复合绘图功能 这意味着您可以在文本视图内部而不是外部添加可绘图项 即: 这也会更快,因为您可以一次性删除视图组和视图(使用的越少,速度越快) 或者,您还可以使用android:drawablePadd

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

就像这张照片:

我希望这样,当文本接触到ImageIiew时,它会显示
,以指示文本继续

row.xml



您可以利用复合绘图功能
这意味着您可以在文本视图内部而不是外部添加可绘图项

即:


这也会更快,因为您可以一次性删除视图组和视图(使用的越少,速度越快)


或者,您还可以使用
android:drawablePadding
属性来设置复合可绘制内容和文本之间的边距,而不是将ImageView和TextView放在相对视图中,您可以利用复合可绘制内容
这意味着您可以在文本视图内部而不是外部添加可绘图项

即:


这也会更快,因为您可以一次性删除视图组和视图(使用的越少,速度越快)


或者,您还可以通过使用
android:drawablePadding
属性来设置复合可绘图项和文本之间的边距,请尝试以下代码。希望它能起作用

<?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>

尝试以下代码。希望它能起作用

<?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>

使用此代码

<?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"
    android:orientation="horizontal">


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

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

            <TextView
                android:id="@+id/txt_file_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="bjbjgbdgkgbndbndkbdkb..fg.bgbfgnbnfgb."
                android:layout_toEndOf="@+id/imageView"
                android:layout_toRightOf="@+id/imageView"
                android:layout_centerVertical="true"/>

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

使用此代码

<?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"
    android:orientation="horizontal">


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

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

            <TextView
                android:id="@+id/txt_file_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="bjbjgbdgkgbndbndkbdkb..fg.bgbfgnbnfgb."
                android:layout_toEndOf="@+id/imageView"
                android:layout_toRightOf="@+id/imageView"
                android:layout_centerVertical="true"/>

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


尝试添加drawableleft(放置drawableleft图像)和Pudding drawablepadding与您的文本视图显示您想要的屏幕截图。@Ironman我从我的目标添加屏幕截图。尝试添加drawableleft(放置DrawableImage)并将padding drawablepadding与您的文本视图一起显示您想要的屏幕截图。@Ironman我从我的目标添加了屏幕截图。这是经过测试的。它的工作原理:O。我的输出端我的平均值不适合我!这是经过测试的。它的工作原理:O。我的输出端我的平均值不适合我!