0

I have a view (Seekbar) in which i am setting a drawable shape named seek_bar.xml in progressDrawable, but i am getting different result when i run the layout in different level api. Means when i run the layout in <21 the shape size seems too small but when i run the layout >=21 shape size seems perfect, please help me how to fix this api level issue for this layout. See the images.

and my appcompct version is.

compile 'com.android.support:appcompat-v7:23.1.1'

<21 api level layout look >=21 api level looks perfect

I have a view named confirm.xml code looks like

    <LinearLayout
    android:layout_centerInParent="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/dialog_background"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:id="@+id/txt_dia"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="40dp"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="@string/dialog_title_logout"
        android:textColor="@color/gray_dark"
        android:textSize="@dimen/dialog_text_title"
        android:textStyle="bold"
        >
    </TextView>

    <RelativeLayout
        android:id="@+id/yes_no_back_strip"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_below="@+id/swipe_btn"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        >

        <SeekBar
            android:id="@+id/unlockButton"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="false"
            android:max="100"
            android:progress="50"
            android:thumb="@drawable/slide_thumb"
            android:splitTrack="false"
            android:paddingLeft="1dp"
            android:paddingRight="1dp"
            android:thumbOffset="1dp"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:progressDrawable="@drawable/seek_bar"
            />

        <LinearLayout
            android:id="@+id/yes_no_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:visibility="visible"
            >

            <TextView
                android:id="@+id/confirm_btn"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="left|center_vertical"
                android:paddingLeft="15dp"
                android:text="@string/btn_txt_yes"
                android:textColor="@color/gray_light_high"
                android:textSize="@dimen/common_text_size"
                android:textStyle="bold"
                />

            <TextView
                android:id="@+id/cancel_btn"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:gravity="right|center_vertical"
                android:paddingRight="15dp"
                android:text="@string/btn_txt_no"
                android:textColor="@color/gray_light_high"
                android:textSize="@dimen/common_text_size"
                android:textStyle="bold"
                />
        </LinearLayout>

    </RelativeLayout>

</LinearLayout>

and my seek_bar.xml is ....

     <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@android:id/background">
        <shape>

            <gradient
                android:angle="0"
                android:startColor="#ffe0db"
                android:centerColor="#aeff6960"
                android:endColor="#ff0002"
                />
            <corners android:radius="35dip" />
            <size android:height="49dp"
                  android:width="190dp"/>
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip >
            <shape>
                <gradient
                    android:angle="0"
                    android:startColor="#0b6e07"
                    android:centerColor="#75ba70"
                    android:endColor="#97ba93"
                   />
                <corners android:radius="35dp"
                    />
                <size android:height="49dp"
                      android:width="190dp"/>
            </shape>
        </clip>
    </item>
</layer-list>
Bajrang Hudda
  • 3,028
  • 1
  • 36
  • 63

1 Answers1

2

In api level >20 android:width and android:height not works with shape, i mean it well automatically detect the correct height and width accordingly to the view but it is not the case when you are using the api level <20. So when you fix the min width and height it will remains fixed through out all the api levels. Otherwise you can specify different -2 layout size. Just add minHight and maxHight in your seekbar layout

<Seekbar
    .....
    android:minHeight="50dp"
    android:maxHeight="50dp"
    ....
 />
Bajrang Hudda
  • 3,028
  • 1
  • 36
  • 63