android长textview封面imageview

问题描述 投票:0回答:4

我有一些问题,右边有长文字和图片。我知道这个问题在stackoverflow上很受欢迎,但是我很开心,我不知道如何在我自己的项目中采用一些解决方案。因此,当textview中的文本很长时,imageview会出现。我尝试使用layout_weigth但没有任何作用。

在这个屏幕上你可以看到只有第三个元素显示右箭头。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="bottom"
        >


        <ImageView
            android:src="@drawable/data"
            android:id="@+id/image_date"
            android:layout_width="20dp"
            android:layout_height="20dp"
            />

        <TextView
            android:id="@+id/date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:lines="1"
            android:ellipsize="end"
            android:textColor="#37a"
            android:textSize="15sp" />

        <ImageView
            android:src="@drawable/gps"
            android:id="@+id/image_gps"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_marginRight="5dp"
            />

        <TextView
            android:id="@+id/address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#37a"
            android:text="Starówka"
            android:lines="1"
            android:ellipsize="end"
            android:textSize="15sp" />


        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="right"
            >

        <ImageView
            android:src="@drawable/iprzod"
            android:id="@+id/image_data"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            />
        </LinearLayout>

        </LinearLayout>
android textview imageview android-layout-weight
4个回答
1
投票

改变这样的代码并尝试

<TextView
        android:id="@+id/address"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="#37a"
        android:text="Starówka"
        android:lines="1"
        android:ellipsize="end"
        android:textSize="15sp" />

此外,您可以删除第二个线性布局(包含唯一的图像)。这不是必需的。用图像替换它


1
投票

第一,

机器人:layout_alignParentTop = “真”

机器人:layout_alignParentRight = “真”

在LinearLayout的子节点中不起作用,LinearLayout面向像Table的单行(水平)或单列(垂直)

要解决此问题,您必须将宽度设置为左侧imageView并将其layout_weight设置为0,以严格保留其宽度,并将所有其他视图移动到另一个LinearLayout中并将其设置为1

- LinearLayout
    - ImageView with width = 300 and weight = 0
    - LinearLayout
        - TextView with width = match_parent and weight = 1
        - another views....

1
投票

谢谢大家的帮助。您的帖子帮助我找到了解决方案。 Finnaly我在textView和LinearLayout中添加了两行,其中包含ImageView它似乎有效,这种方式最容易解决我的问题。

android:layout_width="0dp"
android:layout_weight="1"

0
投票

试试这个 :

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:src="@drawable/temp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20-20-20"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"/>

        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:src="@drawable/temp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys"
            android:lines="1"
            android:ellipsize="end"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/cmj_edit"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_gravity="end"
            android:src="@drawable/edit_pen" />
    </LinearLayout>

</LinearLayout>

为线性布局增加重量。 android:layout_weight="1"

© www.soinside.com 2019 - 2024. All rights reserved.