【发布时间】:2013-11-02 15:22:33
【问题描述】:
对于ListView,我想为单个ListView 元素提供某种进度指示器——可以这么说,我需要一个进度条列表。
但是,每个列表视图元素都有一些 TextView 形式的文本覆盖,根本不受进度条的影响。
在这种情况下,我认为图片比文字更能说明问题,所以这就是我想要的:
我知道我可以将“子布局”添加到个人 LinearLayouts 并以编程方式更改权重,看起来有点像这样:
<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="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@leftSide"
android:background="@color/green"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.8" >
</LinearLayout>
<LinearLayout
android:id="@rightSide"
android:background="@color/red"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2" >
</LinearLayout>
</LinearLayout>
然后以编程方式更改双方的权重(已完成和未完成):
float weightLeft = 0.8f;
float weightRight = 1f-weightLeft;
android.widget.LinearLayout.LayoutParams paramsLeft = new android.widget.LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, weightLeft);
LinearLayout left = (LinearLayout) findViewById(R.id.leftside);
left.setLayoutParams(paramsLeft);
android.widget.LinearLayout.LayoutParams paramsRight = new android.widget.LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, weightRight);
LinearLayout right = (LinearLayout) findViewById(R.id.rightside);
left.setLayoutParams(paramsRight);
但是 - 现在的问题是,我如何让 textviews 坐在父线性布局上并忽略孩子 LinearLayouts ?
我还可以想象有一种方法可以使用drawables 来拆分背景部分的分布,但我不知道如何做到这一点,尤其是不以编程方式。
感谢任何帮助!
【问题讨论】:
标签: java android layout background styles