android长textview封面imageview

时间:2017-12-28 10:25:19

标签: android textview imageview android-layout-weight

我在右侧有长文字和图片时遇到问题。 我知道这个问题在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> ,但没有任何作用。

image

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

coerce

4 个答案:

答案 0 :(得分: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 :(得分: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....

答案 2 :(得分:1)

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

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

答案 3 :(得分: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"