Android-layout_weight不起作用 [英] Android - layout_weight not working

查看:200
本文介绍了Android-layout_weight不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:minHeight="40dp" >

    <LinearLayout
        android:id="@+id/contentLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/separatorView"
        android:weightSum="3"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/itemTitleLabel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@null"
            android:gravity="right"
            android:lines="0"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="5dp"
            android:textColor="@android:color/black"
            android:textSize="16sp"
            android:textStyle="bold" />

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:background="@android:color/white" >

            <TextView
                android:id="@+id/itemDetailsLabel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@null"
                android:gravity="left"
                android:lines="0"
                android:paddingBottom="5dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingTop="5dp"
                android:textColor="@android:color/black"
                android:textSize="16sp"
                android:textStyle="normal" />

            <ImageView
                android:id="@+id/itemAvailabilityImageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@null"
                android:paddingBottom="5dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingTop="5dp"
                android:scaleType="centerInside" />
        </RelativeLayout>
    </LinearLayout>

    <View
        android:id="@+id/separatorView"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentBottom="true"
        android:background="@color/tab_bar_separator" />

</RelativeLayout>

这是列表视图中的行布局.显示的只是最后一个视图. ID为= SeparatorView的那个.

This is a row layout in a list view. What's shown is the last view only. The one with the id = separatorView.

更新:

推荐答案

您应在最后一个View元素(分隔符)中指定

You should specify in your last View element (The separator)

android:layout_below="@id/ContentLayout"

为确保分离部分不会与RelativeLayout的顶部对齐.

To make sure the separatoe won't be aligned to the top of the RelativeLayout.

这篇关于Android-layout_weight不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆