program tip

Android 버튼 개체 내에서 텍스트 주변의 안쪽 여백을 줄이려면 어떻게해야합니까?

radiobox 2020. 10. 18. 09:13
반응형

Android 버튼 개체 내에서 텍스트 주변의 안쪽 여백을 줄이려면 어떻게해야합니까?


버튼 예

그래서 지금은 위의 첫 번째 이미지와 같은 버튼이 있습니다. 버튼 자체 내부의 텍스트 주위의 패딩을 줄이려면 어떻게해야합니까 (두 번째 이미지처럼 보이기 위해)?

레이아웃 너비 및 높이는 다음과 같이 설정됩니다.

android:layout_width="match_parent"
android:layout_height="wrap_content"

사용자 정의 스타일 모양에는 매개 변수가 있습니다. "

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">

나머지는 색상 속성과 반경 값입니다.

명확하게하기 위해 버튼의 프레임이 "로그인"텍스트를 더 가깝게 감싸고 싶습니다.

모든 도움과 피드백에 감사드립니다. 감사.


이것을 찾는 데 영원히 걸렸지 만 버튼의 텍스트 주변의 "패딩"은 실제로 패딩이 아닙니다. 기본 Widget.Button 스타일에는 minHeight 속성이 포함됩니다. 버튼의 minHeight를 변경하면 예상대로 패딩을 조정할 수 있습니다.

<Button
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/test"
        android:textColor="@color/black"
        android:minHeight="40dip"/>


<style name="Widget.Holo.Button" parent="Widget.Button">
    <item name="android:background">@android:drawable/btn_default_holo_dark</item>
    <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
    <item name="android:textColor">@android:color/primary_text_holo_dark</item>
    <item name="android:minHeight">48dip</item>
    <item name="android:minWidth">64dip</item>
</style>

사용자 정의 shape.xml 파일에서 이것을 시도하십시오.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="1dp"
android:padding="1dp">

또한 버튼의 xml을 변경할 수 있습니다.

android:layout_width="wrap_content"
android:layout_height="wrap_content"

더 작은 상단 및 하단 패딩을 원한다면 다음을 사용하십시오.

 android:paddingTop="2dp"
 android:paddingBottom="2dp"

참고 URL : https://stackoverflow.com/questions/16394252/how-do-i-reduce-the-inner-padding-around-the-text-within-an-android-button-objec

반응형