首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义查找栏不能正常工作

自定义查找栏不能正常工作
EN

Stack Overflow用户
提问于 2016-05-25 13:32:52
回答 1查看 371关注 0票数 0

朋友们,帮帮我。我在项目中有一个定制的SeekBar。它没有正确显示。http://take.ms/NgHW9

代码语言:javascript
复制
                                  <LinearLayout
                                        android:layout_width="match_parent"
                                        android:layout_height="wrap_content"
                                        android:layout_weight="1"
                                        android:background="@mipmap/ballance_bg"
                                        android:gravity="center"
                                        android:padding="2dp">

                                        <SeekBar
                                            android:id="@+id/seekBar"
                                            android:layout_width="match_parent"
                                            android:layout_height="wrap_content"
                                            android:layout_gravity="center"
                                            android:clickable="false"
                                            android:focusable="false"
                                            android:max="1"
                                            android:maxHeight="5dp"
                                            android:minHeight="1dp"
                                            android:paddingLeft="1dp"
                                            android:paddingRight="1dp"
                                            android:progress="0"
                                            android:progressDrawable="@drawable/seekbar_progress"
                                            android:saveEnabled="true"
                                            android:thumb="@mipmap/point_icon"
                                            android:thumbOffset="0dp" />
                                    </LinearLayout>

有自定义的可绘制资源- seekbar_progress

代码语言:javascript
复制
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:id="@android:id/background">
    <nine-patch
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@mipmap/like_line_2"
        android:dither="true"/>
</item>
<item
    android:id="@android:id/progress"
    android:drawable="@drawable/red_seekbar_progress" /></layer-list>

like_line_2为9.补丁图像

有自定义的可绘制资源- red_seekbar_progress

代码语言:javascript
复制
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
    <clip>
        <nine-patch
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:src="@mipmap/dislike_line_2"
            android:dither="true"
            />
    </clip>
</item></layer-list>

dislike_line_2为9.补丁图像

此代码填充SeekBar。

代码语言:javascript
复制
seek_1 = (SeekBar) view.findViewById(R.id.seekBar);
seek_1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    return true;
}
});
int sum = Integer.parseInt(products.get(0).getPositive_count()) + Integer.parseInt(products.get(0).getNegative_count());
seek_1.setMax(sum);
seek_1.setProgress(Integer.parseInt(products.get(0).getNegative_count()));

此错误出现在不同的SeekBars中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-09 08:26:02

我自己找到了解决方案。那就是错误的地方。

代码语言:javascript
复制
 <item
android:id="@android:id/progress"
android:drawable="@drawable/red_seekbar_progress" /> 

尽量不要在另一个XML项中使用XML。

正确版本:

代码语言:javascript
复制
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><item android:id="@android:id/background">
<nine-patch
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@mipmap/like_line_2"
    android:dither="true"/>
</item>
<item
     android:id="@android:id/progress">
    <clip>
       <nine-patch
           xmlns:android="http://schemas.android.com/apk/res/android"
           android:src="@mipmap/dislike_line_2"
           android:dither="true"/>
    </clip>
   </item>
</layer-list>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37438809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档