2015-12-14 13 views
7

Tôi có một tuỳ chỉnh seekbar không hoạt động.Làm cách nào để đặt kích thước ProgressDrawable của thanh tìm kiếm tùy chỉnh nhỏ hơn ProgressBackground

Tôi muốn seekbar trông như thế này:

Notice the progress bar is 'skinnier' than the background

Nhưng điều này là gần như là tôi đã có thể để có được

The progress bar and background are the same size

Bỏ qua những vấn đề màu và kích thước nhẹ , vấn đề tôi gặp phải là với kích thước màu xanh lá cây progress. Có cách nào để làm điều này nhỏ hơn nền không? Tôi đã thử các thẻ sizepadding trong số XML và thậm chí đã thử sử dụng hai hình chữ nhật trên đầu trang với clip gravity, nhưng chưa có may mắn.

Đây là tôi Seekbar drawable

<?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 android:shape="rectangle"> 
      <corners android:radius="20dp" /> 
      <solid android:color="@color/fofo_grey" /> 

     </shape> 
    </item> 

    <item android:id="@android:id/progress"> 

     <clip> 
      <shape android:shape="rectangle"> 
       <corners android:radius="20dp" /> 
        <solid android:color="@color/signup_green" /> 
      </shape> 
    </clip> 
    </item> 

</layer-list> 

Và Seekbar trong đoạn bố trí

<SeekBar 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/seekBar" 
    android:layout_below="@+id/textView6" 
    android:layout_centerHorizontal="true" 
    android:splitTrack="false" 
    android:progressDrawable="@drawable/custom_seekbar" 
    android:thumb="@drawable/thumb_seekbar" 
    android:max="100" 
    android:progress="50" 
    android:indeterminate="false" /> 
+0

SeekBar seekBar = (SeekBar) findViewById (R.id.seekBar); seekBar.setScaleY (2f); seekBar.setScaleX (2f); –

+0

Không may mắn ở đây tôi sợ, điều này vừa làm cho toàn bộ 'Seekbar' trở nên to lớn. – BlitzKraig

Trả lời

9
<?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 android:shape="rectangle"> 
      <corners android:radius="20dp"/> 
      <solid android:color="@color/fofo_grey" /> 

     </shape> 
    </item> 

    <item android:id="@android:id/progress"> 

     <clip> 
      <shape android:shape="rectangle"> 
       <corners android:radius="20dp"/> 
        <solid android:color="@color/signup_green" /> 
       <stroke android:width="6dp" 
         android:color="@color/fofo_grey" /> 
      </shape> 
    </clip> 
    </item> 

</layer-list> 

chỉ cần thêm thuộc tính đột quỵ ở seekbar drawable

+0

Cảm ơn David, đã đến giải pháp này trong câu trả lời của riêng tôi. Tôi sẽ đánh dấu của bạn là chấp nhận mặc dù, kể từ khi bạn đã được trên tiền. – BlitzKraig

+0

Điều này phù hợp với tôi sau khi dành cả ngày. –

5

Managed để sửa lỗi này. Không thể tin được nó đã cho tôi quá lâu để nghĩ ra giải pháp ...

<clip> 
      <shape android:shape="rectangle"> 
       <stroke android:color="@color/fofo_grey" android:width="6dp"/> 
       <corners android:radius="20dp" /> 
       <solid android:color="@color/signup_green" /> 
      </shape> 
     </clip> 

Added một stroke với màu sắc tương tự như các yếu tố nền tảng, và tinh chỉnh các strokewidth để đạt được hiệu quả mong muốn.

Finished effect

7

cho sự tiến bộ thay đổi chiều cao drawble chỉ cần thêm android:minHeight="2dip"android:maxHeight="2dip" để pseekbar xml

+0

Cảm ơn bạn. Giải pháp này làm việc cho tôi <3 – ThanosFisherman

Các vấn đề liên quan