패딩은 영향을주지 않습니다. XML 레이아웃
<shape>
XML 파일 / 레이아웃 내 에서 선언 된 패딩을 설정하려고 합니다. 그러나 내가 설정 한 것이 무엇이든 패딩과 관련된 변경 사항은 없습니다. 다른 속성을 수정하면 UI에 효과가 나타납니다. 그러나 패딩에서는 작동하지 않습니다. 이것이 발생할 수있는 가능한 이유에 대해 조언 해 주시겠습니까?
스타일을 지정하려는 XML 셰이프는 다음과 같습니다.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp"
android:color="#ffffff"
android:dashWidth="2dp"/>
<solid android:color="@color/button_white_cover"/>
<corners android:radius="11dp"/>
<padding android:left="1dp"
android:top="20dp"
android:right="20dp"
android:bottom="2dp"/>
</shape>
마침내 패딩 문제를 해결했습니다.
따라서 여기의 패딩은 모양에 영향을주지 않습니다. 대신, 그것을 사용할 다른 드로어 블에 패딩을 적용해야합니다. 그래서 모양을 사용하는 드로어 블이 있고 거기에서 다음을 수행합니다.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_below"/>
<item android:top="10px" android:right="10px" android:drawable="@drawable/shape_cover"/>
</layer-list>
따라서 두 번째 <item>
요소 에서 볼 수 있듯이 패딩 (위쪽과 오른쪽)을 설정했습니다. 그리고 그 후에 모든 것이 작동합니다.
감사.
코멘트를 한 부부가 언급했듯이, 가장 좋은 방법은을 래핑하는 것입니다 <shape>
에 <item>
요소 대신에 거기에 패딩을 설정합니다. 그러나 아래 링크에 자세히 설명 된 다른 옵션이 있습니다. 예 :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="8dp"
android:right="8dp"
android:top="8dp"
android:bottom="8dp">
<shape android:shape="rectangle">
...
</shape>
</item>
</layer-list>
필요에 따라 레이어 목록을 사용하는 대신 다음 드로어 블 유형 중 하나를 사용할 수 있습니다.
- 레이어 목록
- 선택자
- 레벨 목록
- 전이
사용 가능한 드로어 블 유형에 대한 자세한 내용은 이 Android 문서를 참조 하세요.
출처 :
- DustinB의 코멘트
- 야헬의 대답
- user924의 코멘트
- Android에서 그라디언트 <shape>에 패딩을 추가하는 방법은 무엇입니까?
Lyobomyr의 대답은 작동하지만 여기에는 동일한 솔루션이 적용되지만 새로운 드로어 블을 만드는 오버 헤드가 없으므로 파일 혼란을 최소화합니다.
https://stackoverflow.com/a/3588976/578746
Copy/Paste of the anwser by anon on the SO answer above :
<item android:left="6dp"
android:right="6dp">
<shape android:shape="rectangle">
<gradient android:startColor="#ccd0d3"
android:centerColor="#b6babd"
android:endColor="#ccd0d3"
android:height="1px"
android:angle="0"/>
</shape>
</item>
You can try insets:
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetBottom="2dp"
android:insetLeft="1dp"
android:insetRight="20dp"
android:insetTop="20dp">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#ffffff"
android:dashWidth="2dp" />
<solid android:color="@color/button_white_cover" />
<corners android:radius="11dp" />
</shape>
</inset>
I solved this problem like this:
<shape android:shape="oval" >
<stroke android:width="4dp" android:color="@android:color/transparent" />
<solid android:color="@color/colorAccent" />
</shape>
just added a transparent stroke to it.
참고URL : https://stackoverflow.com/questions/1283085/padding-doesnt-affect-shape-in-an-xml-layout
'Nice programing' 카테고리의 다른 글
PowerShell을 사용하여 폴더의 항목 계산 (0) | 2020.10.25 |
---|---|
C #과 유사한 JavaScript에서 숫자 형식 지정 (0) | 2020.10.25 |
입력 길이를 3으로 나눌 수없는 경우 base64 인코딩에 패딩이 필요한 이유는 무엇입니까? (0) | 2020.10.25 |
코드에서 여백 속성 설정 (0) | 2020.10.25 |
“NoClassDefFoundError : 클래스를 초기화 할 수 없습니다.”오류 (0) | 2020.10.25 |