小编use*_*247的帖子

如何以编程方式创建具有所需背景颜色的Drawable?

我需要创建一个Drawable具有所需颜色作为背景颜色的简单对象,但我不知道如何在不使用XML模式的情况下以编程方式执行此操作(可能真的吗?).请告诉我,我需要它来制作LayerDrawable和使用SeekBar(以SeekBar编程方式更改背景).先感谢您.

android

15
推荐指数
3
解决办法
2万
查看次数

RelativeLayout的layout_weight不起作用

有以下代码:

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.9"
            android:gravity="center"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/activityEvaluationYesterdayValueDisplay"
                android:layout_width="15dip"
                android:layout_height="wrap_content"
                android:text="0"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textStyle="bold" />

            <com.ulnda.mypsych.views.VerticalSeekBar
                android:id="@+id/activityEvaluationYesterdayValue"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:max="10"
                android:progress="0" />
        </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

现在我需要将LinearLayout更改为RelativeLayout.如果我这样做,那么RelativeLayout会填满整个屏幕,这很糟糕.我知道RelativeLayout不使用layout_weight来完成它的工作.请告诉我,我该如何解决?我试图为RelativeLayout制作LinearLayout包装器,但它没有帮助.

更新:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.6"
        android:orientation="vertical" >

        <RelativeLayout
            android:background="#000000"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </RelativeLayout>

    </LinearLayout>

</LinearLayout>
UPDATE 2: FUll code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.5" >

            <LinearLayout
                android:weightSum="1.0"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.33"
                android:orientation="vertical" > …
Run Code Online (Sandbox Code Playgroud)

android

1
推荐指数
1
解决办法
6291
查看次数

标签 统计

android ×2