Android的 - 不能把拇指放在一个搜索栏的中心放在、能把、拇指、中心

2023-09-07 15:41:59 作者:别在劳资面前说老凉°

我想知道如何在搜索栏的中心设立大拇指。不知道怎么给前preSS,所以我将添加一个图片的链接。第一IMG是从设计导向一个搜索栏,以及初级讲座是我seekbars。

(忽略有关的角落。我固定捕捉IMGS后)。 首先,从设计师,我得到了那些文字的两个独立的IMG,好的和坏的。所以我结合这些。我认为这会工作为拇指。但现在我得到的是这种结果......请帮助我..谢谢!

绘制:progressbar_goodbad XML

 <?XML版本=1.0编码=UTF-8&GT?;<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android><项目机器人:ID =@机器人:ID /背景>    <形状和GT;        <梯度            机器人:startColor =#f5c0bd            机器人:centerColor =#f5c0bd            机器人:centerY =0.75            机器人:ENDCOLOR =#f5c0bd            机器人:角=270/>        <填充机器人:左=10dp            机器人:顶部=1DP            机器人:右=10dp            机器人:底部=1DP/>    <角落        机器人:bottomRightRadius =10dp        机器人:bottomLeftRadius =10dp        机器人:topLeftRadius =10dp        机器人:topRightRadius =10dp/>< /形状>< /项目><项目机器人:ID =@机器人:ID / secondaryProgress><夹>    <形状和GT;        <梯度            机器人:startColor =#234            机器人:centerColor =#234            机器人:centerY =0.75            机器人:ENDCOLOR =#A24            机器人:角=90/>        <填充机器人:左=1DP            机器人:顶部=1DP            机器人:右=1DP            机器人:底部=1DP/>    <角落        机器人:bottomRightRadius =10dp        机器人:bottomLeftRadius =10dp        机器人:topLeftRadius =10dp        机器人:topRightRadius =10dp/>        < /形状>< /夹>< /项目><项目机器人:ID =@机器人:ID /进度><夹>   <形状和GT;        <梯度            机器人:startColor =#fc9a94            机器人:centerColor =#fc9a94            机器人:centerY =0.75            机器人:ENDCOLOR =#fc9a94            机器人:角=90/>        <填充机器人:左=1DP            机器人:顶部=1DP            机器人:右=1DP            机器人:底部=1DP/>    <角落        机器人:bottomRightRadius =10dp        机器人:bottomLeftRadius =10dp        机器人:topLeftRadius =10dp        机器人:topRightRadius =10dp/>    < /形状>< /夹>< /项目>< /层列表> 

主要布局XML的部分

 <搜索栏     机器人:ID =@ + ID / seekBar_fun     机器人:layout_width =FILL_PARENT     机器人:layout_height =WRAP_CONTENT     机器人:layout_marginBottom =3DP     机器人:paddingLeft =10dp     机器人:paddingRight =10dp     机器人:最大=100     机器人:进度=60     机器人:progressDrawable =@绘制/ progressbar_goodbad     机器人:拇指=@绘制/ f_02_good_bad_text/> 

解决方案

(回答Twinsens链接找到。)

拇指推安卓版下载 拇指推 2.0 android手机版 河东软件园

您的拇指图片需要有它的在中心黄点(水平);添加透明像素向左或向右,使其左右。然后,将的android:thumbOffset 是正好有一半拇指图像大小。例如,如果您的图像 10dp 的宽度,设置的android:thumbOffset 为 5DP

I want to know how to set thumb at center of a seekbar. Don't know how to express, so i'll add link of a pic. first img is a seekbar from design guides, and the belows are my seekbars.

(ignore about corners. I fixed after capturing the imgs.) at first, from designer, i got two separate img of those text, good and bad. so i combined those. i thought it would work as thumb. but now what i got is these result... please help me.. thank you!

drawable : progressbar_goodbad 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">
    <shape>
        <gradient
            android:startColor="#f5c0bd"
            android:centerColor="#f5c0bd"
            android:centerY="0.75"
            android:endColor="#f5c0bd"
            android:angle="270"/>
        <padding android:left="10dp"
            android:top="1dp"
            android:right="10dp"
            android:bottom="1dp"/> 
    <corners
        android:bottomRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
    <shape>
        <gradient
            android:startColor="#234"
            android:centerColor="#234"
            android:centerY="0.75"
            android:endColor="#a24"
            android:angle="90"/>
        <padding android:left="1dp"
            android:top="1dp"
            android:right="1dp"
            android:bottom="1dp"/> 
    <corners
        android:bottomRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"/>
        </shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
   <shape>
        <gradient
            android:startColor="#fc9a94"
            android:centerColor="#fc9a94"
            android:centerY="0.75"
            android:endColor="#fc9a94"
            android:angle="90"/>
        <padding android:left="1dp"
            android:top="1dp"
            android:right="1dp"
            android:bottom="1dp"/> 
    <corners
        android:bottomRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"/>
    </shape>
</clip>
</item>
</layer-list>

part of main layout xml

<SeekBar
     android:id="@+id/seekBar_fun"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_marginBottom="3dp"
     android:paddingLeft="10dp"
     android:paddingRight="10dp"
     android:max="100"
     android:progress="60"
     android:progressDrawable="@drawable/progressbar_goodbad"
     android:thumb="@drawable/f_02_good_bad_text" />

解决方案

(Answer found in Twinsens link.)

Your thumb image needs to have it's yellow dot at the center (horizontally); add transparent pixels left or right to make it so. Then, change android:thumbOffset to be exactly half your thumb image size. For example, if your image is 10dp in width, set android:thumbOffset to 5dp.