【问题标题】:table layout problemss in custom listview android自定义listview android中的表格布局问题
【发布时间】:2015-08-20 13:50:44
【问题描述】:

我创建了一个带有表格布局的自定义列表视图。 现在我想显示右边的文字。 (你可以在图片中看到一个例子,我不能把这个放在帖子里)

但我无法将文本视图向右移动。

http://i.stack.imgur.com/x57ly.png

我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="top"
    android:background="@drawable/bar_bg"
    android:paddingTop="0dip" >

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        tools:ignore="RtlHardcoded" >

        <TableRow
            android:layout_marginTop="3dp"
            tools:ignore="UselessParent"
             >

            <LinearLayout
                android:layout_width="120dp"
                android:layout_height="82dp"
                android:paddingBottom="5dp"
                android:paddingLeft="5dp"
                android:paddingTop="5dp"
                tools:ignore="RtlSymmetry" >

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:layout_gravity="left|top"
                    android:scaleType="centerCrop"
                    tools:ignore="ContentDescription" />

            </LinearLayout>

            <TableLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="top"
                android:paddingTop="0dp" >

                <TableRow
                    android:layout_width="fill_parent"
                    android:layout_gravity="center_vertical"
                    android:textDirection="rtl"
                    tools:ignore="UnusedAttribute" >

                    <TextView
                        android:id="@+id/text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right|center_vertical"
                        android:layout_marginLeft="5dp"
                        android:layout_marginTop="9dp"
                        android:layout_marginBottom="10dp"
                 android:paddingRight="6dp"
                        android:gravity="right"
                        android:layout_span="1"
                        android:layout_weight="1"
                        android:textColor="#000000"
                        android:textSize="16sp" />
                </TableRow>

                <TableRow android:layout_width="fill_parent" >

                    <TextView
                        android:id="@+id/text1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right|center_vertical"
                        android:layout_marginBottom="10dp"
                        android:layout_marginLeft="5dp"
                        android:layout_marginTop="5dp"
                        android:layout_weight="1"
             android:gravity="right"        
             android:paddingRight="6dp"
                        android:textColor="#000000"
                        android:textSize="16sp"
                        tools:ignore="RtlHardcoded" />

                </TableRow>
            </TableLayout>
        </TableRow>
    </TableLayout>

    <TextView
        android:id="@+id/tvdarsad"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="16dp"
        android:textSize="22sp"
        android:textAlignment="center"
        android:textStyle="bold"
        android:layout_marginTop="18dp"
        android:background="@drawable/badge_ifaux"
        android:text="%20"
        android:textColor="#FFFFFF" />

    <ImageView
        android:id="@+id/imagecolor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginTop="15dp"
        android:layout_marginRight="4dp"
        android:layout_alignParentTop="true"
        android:src="@drawable/color1"/>

</RelativeLayout>

【问题讨论】:

  • 如果您的目标是创建表格,请查看此自定义 Android TableView

标签: android android-listview


【解决方案1】:

我认为您实施了一个复杂的解决方案。您可以使用 LinearLayout 并在其视图之间分配权重来实现相同的结果。

在这里,我发布了一个示例,其中的代码与照片的结果相同。 希望对您有所帮助。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">

<ImageView
    android:id="@+id/image"
    android:layout_width="0dip"
    android:layout_height="match_parent"
    android:layout_weight=".5"
    tools:ignore="ContentDescription" />


<LinearLayout
    android:layout_width="0dip"
    android:layout_height="match_parent"
    android:layout_weight="2"
    android:layout_marginLeft="20dp"
    android:orientation="vertical">


    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="text1"
        android:textColor="#000000"
        android:textSize="16sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="text2"
        android:textColor="#000000"
        android:textSize="16sp" />
</LinearLayout>


<TextView
    android:id="@+id/text2"
    android:layout_width="0dip"
    android:layout_height="match_parent"
    android:layout_weight=".3"
    android:textColor="#000000"
    android:textSize="16sp" />

<ImageView
    android:id="@+id/imagecolor"
    android:layout_width="0dip"
    android:layout_height="match_parent"
    android:layout_weight=".2"
    android:src="@drawable/abc_btn_borderless_material"/>


</LinearLayout>

【讨论】:

  • 为你的 naswer 加油 @marta
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-22
  • 1970-01-01
  • 1970-01-01
  • 2011-02-27
  • 1970-01-01
  • 2013-04-28
相关资源
最近更新 更多