Closed. This question needs to be more focused。它当前不接受答案。












想要改善这个问题吗?更新问题,使它仅关注editing this post的一个问题。

已关闭6年。



Improve this question




我如何做一个listview如下:

还有一个关于行布局的问题,我有这样的布局
<?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" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:background="@drawable/deals_list_row_gradient_background"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/dealImg"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="top"
            android:src="@drawable/test" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/dealDescription"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                android:text="Lorem Ipsum dolor sit amet dolor sed a ite amkt Lantin dolor latim dk kuitshen sed iditur anet" />

            <TextView
                android:id="@+id/smth"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="4dp"
                android:text="...................................................."
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <TextView
                    android:id="@+id/dealNewPrice"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="5dp"
                    android:text="1248$"
                    android:textColor="@color/deals_list_new_price"
                    android:textSize="18sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/dealOldPrice"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_marginRight="15dp"
                    android:layout_toLeftOf="@+id/dealNewPrice"
                    android:text="2500$"
                    android:textColor="@color/deals_list_old_price"
                    android:textSize="15sp" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

但是我在imageview上遇到麻烦,我不明白如何正确设置其宽度和高度
也有很多人说我使用RalativeLayout是个坏主意

最佳答案

您可以使用修改后的 ListView 布局轻松完成此操作。这是我的实现方式:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp" />

</RelativeLayout>
这是结果 View :

需要注意的一件事:
此屏幕快照是在xhdpi设备上拍摄的-您可以看到虚线问题。考虑改用ShapeDrawable并指定android:dashGapandroid:dashWidth

10-07 19:13
查看更多