如何在不超过固定大小的情况下将布局包装到其视图中? [英] How to wrap a layout to its views without exceeding a fixed size?

查看:52
本文介绍了如何在不超过固定大小的情况下将布局包装到其视图中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此布局以具有三个固定的视图:

I am using this layout in order to have three fixed views:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:textColor="#372c24" 
        android:paddingLeft="10dp"/>

    <View
        android:id="@+id/space"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:background="@android:color/transparent" />

    <LinearLayout
        android:id="@+id/ratingLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:orientation="horizontal" 
        android:background="@drawable/shape_popup">
        <TextView
            android:id="@+id/rateNumber"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:gravity="center_horizontal"
            android:paddingTop="2dp" 
          />
        <ImageView
            android:contentDescription="@string/app_name"
            android:id="@+id/rateStar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/rate_star"/>
    </LinearLayout>

</LinearLayout>

我希望我的ratingLayout包装其内容,但不要超过其固定大小.有可能吗?

I want my ratingLayout to wrap its content but not to exceed its fixed size. Is that possible?

推荐答案

取消在ratingLayout上的权重,并将rateNumber和rateStar视图的layout_width属性设置为"wrap_content"而不是"match_parent".

Remove the weighting on the ratingLayout, and set the rateNumber and rateStar views' layout_width property to "wrap_content" instead of "match_parent".

这篇关于如何在不超过固定大小的情况下将布局包装到其视图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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