2017-02-05 7 views
0

layer-list을 사용할 때 XML 드로어 블의 너비를 어떻게 지정할 수 있습니까? 드로어 블의 너비를 (전체적으로) 20dp로 설정하길 원하지만, 이것을 설정하는 방법과 미리보기 패널을 설정하는 방법은 그다지 도움이되지 않습니다.전체적으로 레이어 목록의 너비를 설정하는 방법은 무엇입니까?

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape> 
      <solid android:color="@color/blue" /> 
     </shape> 
    </item> 
    <item android:left="8dp" android:right="8dp"> 
     <shape> 
      <solid android:color="#fff" /> 
     </shape> 
    </item> 
</layer-list> 

enter image description here

답변

2

시도해 볼 수 있습니다.

<shape> 
     <solid android:color="#fff"/> 
     <size android:height="10dp" android:width="20dp"/> 
    </shape> 
1

좋은 방법은 직접 파일에 XML의 드로어 블의 크기를 구성하지 않습니다. 레이아웃 파일에서보기의 크기를 설정해야합니다.

<Button 
..... 
    android:drawable="@drawable/shape" > 
<Button> 

을하지만 당신은 여전히 ​​크기를 설정하는 wan't 경우이 코드를 사용할 수 있습니다 : 예를 들어 당신이 당신의 코드와 당김 shape.xml의 일부 버튼이있는 경우, 코드는 다음과 같이 할 수

<size android:width="60dp" 
    android:height="40dp" />