LinearLayout填充背景百分比 [英] LinearLayout Fill Percent Of Background
本文介绍了LinearLayout填充背景百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试填充(水平)项目背景的某个百分比。
I am trying to fill a certain percent of a (horizontal) item's background.
我试过这个,因为很多人推荐:
I have tried this as many people have recommended:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:orientation="horizontal"
android:weightSum="1"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/fill_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#000"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
但问题是我在下面有更多的布局,这个布局结束了将其余部分推到了正确如此:
But the problem is that I have many more layout's below that and this layout end's up pushing the rest to the right like so:
如何使这个新的LinearLayout背景布局落后于其余部分布局?这是我的完整xml:
How do I make this new LinearLayout background layout go behind the rest of the layouts? Here is my full xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:background="@color/optionItemBackgroundColor"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground"
android:orientation="horizontal"
android:weightSum="100"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/fill_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:background="@color/percent_fill_color"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="?listPreferredItemHeight"
android:orientation="vertical"
android:weightSum="3">
<TextView
android:id="@+id/percentText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/activity_vertical_margin"
android:layout_weight="2"
android:gravity="center"
android:textColor="@color/optionItemTextColor"
android:textSize="@dimen/option_text_size"
android:textStyle="bold" />
<TextView
android:id="@+id/votesText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/activity_vertical_margin"
android:layout_weight="1"
android:gravity="center"
android:textColor="@color/optionItemTextColor"
android:textSize="@dimen/num_votes_text_size"
android:textStyle="normal" />
</LinearLayout>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/activity_vertical_margin"
android:gravity="center_vertical"
android:minHeight="?listPreferredItemHeight"
android:textColor="@color/optionItemTextColor"
android:textSize="@dimen/option_text_size" />
</LinearLayout>
推荐答案
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/optionItemBackgroundColor"
android:orientation="vertical"
android:weightSum="100"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/fill_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:background="@color/percent_fill_color"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
这篇关于LinearLayout填充背景百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文