布局文件中的最大TextView宽度

时间:2014-05-12 20:58:04

标签: android android-layout

我有一个用于ExpandableListView的parentView的小布局文件 如果TextView文本太长,则会覆盖布局的其他一些视图。

这是一张图片:enter link description here

这是布局文件:

<?xml version="1.0" encoding="utf-8"?>

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

    <TextView
        android:text="test"
        android:id="@+id/file_name"
        android:layout_marginLeft="32dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:textAppearance="?android:textAppearanceLarge"
        android:layout_centerVertical="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_icon_line"
        android:contentDescription="@string/image_placeholder"
        android:layout_toLeftOf="@+id/show_file_detail"
        android:layout_centerVertical="true"/>

    <ImageView
        android:id="@+id/show_file_detail"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_action_next_item"
        android:contentDescription="@string/image_placeholder"
        android:clickable="true"
        android:layout_centerVertical="true"/>

</RelativeLayout>

我已经谷歌解决了问题,但答案并不那么具体 我尝试用android:layout_toLeftOf长文本右对齐,如果显示一个短文本,它看起来很可怜​​。

你们其中任何人都有想法吗?

迎接

1 个答案:

答案 0 :(得分:0)

// try this way,hope this will help you...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:padding="5dp">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginLeft="32dp">
        <TextView
            android:text="test"
            android:id="@+id/file_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:textAppearance="?android:textAppearanceLarge" />
    </LinearLayout>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:contentDescription="@string/image_placeholder"
        android:layout_marginLeft="5dp"/>
    <ImageView
        android:id="@+id/show_file_detail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_action_next_item"
        android:contentDescription="@string/image_placeholder"
        android:layout_marginLeft="5dp"
        android:clickable="true"/>

</LinearLayout>