【问题标题】:Linear Layout with image and Text带有图像和文本的线性布局
【发布时间】:2015-05-28 13:47:30
【问题描述】:

我必须创建具有一个图像和多个文本视图的布局,并且像这样进行评级,并且我已经添加了一条关于使用适配器扩展此布局的行

| Image| Name of Product            |
|       Desc                        |
|       Amount                      |
|       EMI details                 |
|       Rating Sybmol total Rating  |

所以我尝试创建这样的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <LinearLayout
        android:id="@+id/mainLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:orientation="horizontal" >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"
            android:layout_marginTop="5dp"
            android:layout_marginLeft="10dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:id="@+id/text"
            android:text="Micromax Canvas Spark"
            android:textColor="@android:color/black" />
    </LinearLayout>
</RelativeLayout>

但我很困惑如何创建布局,请帮助我

【问题讨论】:

  • 你想让他的图像在他的左边,而 textViews 在右边吗?
  • @EugeneH 是,当我在列表视图中插入时,列表视图中每一行的行
  • 我不太清楚你所说的行是什么意思。
  • 每个列表项之间的分隔符?
  • @EugeneH 是每个列表项中的分隔符

标签: android android-layout android-linearlayout


【解决方案1】:

这就是我假设您正在尝试完成的事情。

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:src="@mipmap/ic_launcher"/>

    <LinearLayout
        android:id="@+id/mainLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="72dp"
        android:orientation="vertical">


        <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="16dp"
            android:text="Micromax Canvas Spark"
            android:textColor="@android:color/black"/>

        <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:text="Micromax Canvas Spark"
            android:textColor="@android:color/black"/>

        <TextView
            android:id="@+id/text2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:text="Micromax Canvas Spark"
            android:textColor="@android:color/black"/>

        <TextView
            android:id="@+id/text3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:text="Micromax Canvas Spark"
            android:textColor="@android:color/black"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp">

            <RatingBar
                android:id="@+id/ratingBar"
                style="?android:attr/ratingBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:rating="2"/>

            <TextView
                android:id="@+id/text4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:text="1003 Votes"
                android:textColor="@android:color/black"/>

        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

ListView 的分隔符

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="#fff"
    android:dividerHeight="1dp"/>

更新

更改评分栏的大小。

 style="?android:attr/ratingBarStyleSmall"
 style="?android:attr/ratingBarStyleIndicator"  // Perfect Size but stars are blue

【讨论】:

  • 如何在此布局中显示评级星或评级符号
  • 我确实在尝试,但我还需要为此显示评级符号
  • 使用评分栏更新布局
  • 在 RatingBar 小部件中添加评分栏样式:style="?android:attr/ratingBarStyleSmall"。
  • @Gaurav 没问题。祝项目的其余部分好运。
【解决方案2】:
I have implemented based on your prototype.

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

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toRightOf="@+id/imageView1"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Name of Product:" />

            <TextView
                android:id="@+id/txt_name_of_Product"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="---" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Desc:" />

            <TextView
                android:id="@+id/txt_desc"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="---" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="AMT:" />

            <TextView
                android:id="@+id/txt_amount"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="---" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="EMI Details:" />

            <TextView
                android:id="@+id/txt_emi_detais"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="---" />
        </LinearLayout>

        <RatingBar
            android:id="@+id/ratingBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleX="0.5"
            android:scaleY="0.5" />
    </LinearLayout>

</RelativeLayout>

【讨论】:

  • 但我们需要在评分栏后添加评分总数??
  • 然后你可以在 Ratingbar 中添加 android:numStars="8" 属性。
  • 不,我必须在评分栏后显示一个包含评分详细信息的文本视图
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-05
  • 1970-01-01
  • 2011-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多