将背景放置在线性布局上,几乎占据了整个屏幕的3/4 [英] Putting a background on the linear layout and takes almost 3/4 of the screen

查看:88
本文介绍了将背景放置在线性布局上,几乎占据了整个屏幕的3/4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了其他帖子提供的各种帮助(将宽度设置为0dp等),但似乎无济于事.

I have tried all kinds of help from other posts (setting widths to 0dp etc.) but nothing seems to work.

我有2种布局,第一种布局似乎仍然占主导地位.如果我将背景色放在文本视图上,则它们的行为会正确并正确结束.但是在线性布局上放一个背景,它几乎是屏幕的3/4!?

I have 2 layouts and the first one still seems to dominate. If I put background colors on the textviews, they are behaving themselves and end correctly. However put a background on the linear layout and it is almost 3/4 of the screen!?

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:id="@+id/rowkRow"
    android:background="@color/RowBkgColor" android:gravity="center_vertical"
    android:minHeight="60dp">
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/rowleftImage"
        android:padding="3dip" android:gravity="left" android:layout_weight="0" />

    <LinearLayout android:orientation="vertical"
        android:layout_weight="0" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/rowtext1"
            android:padding="3dip" android:gravity="left" android:typeface="sans"
            android:textStyle="bold" android:text="First Text" android:textSize="40dp"
            android:textColor="#FF333344" android:visibility="visible" 
             />
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/rowtext3"
            android:padding="3dip" android:gravity="center" android:typeface="sans"
            android:textStyle="bold" android:text="First Text" android:textSize="10dp"
            android:textColor="#FF333344" android:visibility="visible"
            android:background="#606060"
             />
    </LinearLayout>

    <LinearLayout android:orientation="vertical"
        android:layout_weight="1" android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/rowtext4"
            android:padding="3dip" android:gravity="right" android:text="Fourth Text"
            android:textSize="10dp" android:textStyle="bold" android:textColor="@color/RowTextColor"
            android:visibility="visible" />
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/rowtext2"
            android:padding="3dip" android:gravity="left" android:text="Second Text"
            android:textSize="17dp" android:textStyle="bold" android:textColor="@color/RowTextColor"
            />
    </LinearLayout>

    <ImageView android:id="@+id/rowrightImage"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:padding="3dip" android:layout_weight="0" android:gravity="right" />
</TableRow>

推荐答案

执行以下操作.你可以解决你的问题.

Do the following things. U can solve your problem.

  • 将孩子的android:layout_width设置为"0dp"
  • 设置父级的android:weightSum
  • 按比例设置每个孩子的android:layout_weight(例如weightSum = "5",三个孩子:layout_weight="1", layout_weight="3", layout_weight="1")
  • set the android:layout_width of the children to "0dp"
  • set the android:weightSum of the parent
  • set the android:layout_weight of each child proportionally (e.g. weightSum = "5", three children: layout_weight="1", layout_weight="3", layout_weight="1")

这篇关于将背景放置在线性布局上,几乎占据了整个屏幕的3/4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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