我正在尝试使用内部具有数字比例的自定义搜索栏,但不起作用。该搜索栏必须支持所有屏幕分辨率。我怎样才能做到这样。请提出您的宝贵意见。
我的custom_seekbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+android:id/background"
android:drawable="@drawable/unselect"/>
<item
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/select">
</item>
<item
android:id="@android:id/progress"
android:drawable="@drawable/select">
</item>
活动_main.xml
<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:background="@color/default_screen_bg"
android:orientation="vertical"
tools:context=".MainActivity" >
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:indeterminate="false"
android:max="10"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:progressDrawable="@drawable/custom_seekbar" />
</LinearLayout>
取消选择.png
选择.png
我的结果屏幕是这样的
我期待着这样的
问题的解决方案有很多:
- Use 9patch背景图像(基本上是should用作搜索栏的背景)。就像下面这样:
(name should be unselect_patch.9.png
) and slightly modify custom_seekbar.xml
to look like the following:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/unselect_patch"/>
<item android:id="@android:id/secondaryProgress">
<clip>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/select"
android:tileMode="disabled" />
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/select"
android:tileMode="disabled" />
</clip>
</item>
</layer-list>
- 只需在布局中提供图像的精确大小(例如
layout_width="@dimen/select_image_width"
);
要支持所有分辨率 - 提供不同分辨率的图像,如中所述支持多屏。相同的图像并不适用于所有分辨率,最好遵循上面链接中详细描述的最佳实践。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)