【问题标题】:ListView Item layoutListView 项目布局
【发布时间】:2012-04-30 09:28:39
【问题描述】:

我正在设计我的应用程序,但我在设计 ListView 的项目时遇到了一些问题。

附上你可以找到它的样子,以及我想要的样子。

这是项目的布局:

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeight" >

        <TextView android:id="@android:id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="?android:attr/listPreferredItemPaddingLeft"
            android:layout_marginTop="8dip"
            android:textAppearance="?android:attr/textAppearanceListItem"
        />


        <RelativeLayout android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true" >

            <ImageView
            android:id="@+id/favourite_status"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@android:id/text1"
            android:src="@drawable/is_not_favourite"
            android:contentDescription="@string/list_favorites_status"
            android:background="@null"
            android:layout_margin="9dp"/>

        </RelativeLayout>

        <TextView android:id="@android:id/text2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@android:id/text1"
            android:layout_alignLeft="@android:id/text1"
            android:textAppearance="?android:attr/textAppearanceMedium"
        />



  </TwoLineListItem>

问题是文本:我不希望描述在应该为空的空间中溢出。 提前感谢您的帮助。

【问题讨论】:

  • 您使用的是wrapContent 而不是给出值。
  • 这只是正确构建布局的问题。您在上面的布局,您有一个文本视图(您的标题),然后是一个相对布局(您的图像),然后基本上向右浮动,然后是您的最终文本视图(您的描述),它会占用所有剩余空间。
  • 感谢您的帮助。问题是我想把星星下面的空间留空,而不是让文字在里面溢出

标签: android android-layout android-listview android-fragments


【解决方案1】:

很简单,您可以执行以下操作:

<LinearLayout
    ....
    android:orientation="horizontal" 
    ....>
    <LinearLayout
        ....
        android:orientation="vertical" 
        ....>
        <TextView />
        <TextView />
    </LinearLayout>
    <ImageView />
</LinearLayout>

这是一个基本的布局,你也可以用RelativeLayout实现同样的效果

【讨论】:

    猜你喜欢
    • 2020-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多