0

我有一个包含三列的列表视图。第一个是 ImageView,第二个和第三个是 textviews(见代码打击)。

我希望列表像这样对齐:

  1. 图标和日期应始终完整显示!
  2. 中间的文字应该显示尽可能多的字符
  3. 日期应始终在右侧

下面的 XML 在我的 Nexus 4 上看起来不错。但在华硕平板电脑上,日期应该更多在右侧,中间的列应该显示更多文本(屏幕截图 1)。在 AVD(屏幕截图 2)上,中间的列应该更小,日期应该完整显示。

谁能告诉我如何更改 XML?谢谢!

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >

<ImageView
    android:id="@+id/logo"
    android:layout_width="50px"
    android:layout_height="50px"
    android:layout_marginLeft="5px"
    android:layout_marginRight="20px"
    android:layout_marginTop="5px"
    android:src="@drawable/social_chat"
    android:layout_weight="0"
    >
</ImageView>

<TextView
    android:id="@+id/label"
    android:layout_width="0px"
    android:layout_height="fill_parent"
    android:layout_marginTop="0px"
    android:text="@+id/label"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_weight="50"
    android:maxLines="1"
    android:singleLine="true"
    >
</TextView>

<TextView
    android:id="@+id/last_changed"
    android:layout_width="0px"
    android:layout_height="fill_parent"
    android:layout_marginTop="15px"
    android:layout_marginLeft="5px"
    android:text="@+id/last_changed"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:layout_weight="50"
    android:maxLines="1"
    android:singleLine="true"
    >
</TextView>

4

2 回答 2

0

这应该做你的工作。我已将图像视图放在父母左侧,父母右侧的日期以及图像右侧和日期左侧的标签。它应该适合您。边距、内边距请自行填写

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



<ImageView
    android:id="@+id/logo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:src="@drawable/social_chat" />

    <TextView
    android:id="@+id/last_changed"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:singleLine="true" />

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_toLeftOf="@id/last_changed"
    android:layout_toRightOf="@id/logo"
    android:singleLine="true" />
</RelativeLayout>
于 2013-09-25T00:43:51.037 回答
0

在我的脑海中,您的布局看起来像这样。-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/logo"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="5dp"
        android:src="@drawable/social_chat" />

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_weight="1"
        android:singleLine="true" />

    <TextView
        android:id="@+id/last_changed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="5dp"
        android:text="@+id/last_changed"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:singleLine="true" />

</LinearLayout>

这里的关键是wrap_content用于只需要保持其大小的视图,并weight为中间视图设置 a ,您想要填充该行的其余部分。


一些有用的提示。-

  • fill_parent已弃用,请match_parent改用
  • 当视图没有子视图时,您可以将其关闭/>
  • singleLine="true"有一个 singleLined 就足够了TextView
  • 您通常希望使用dp单位而不是px
于 2013-09-24T21:32:43.990 回答