오른쪽에 안드로이드 확인란을 표시하는 방법은 무엇입니까?
기본적으로 안드로이드 확인란은 오른쪽에 텍스트
를 표시하고 왼쪽 에는 확인란을 표시합니다. 왼쪽에 텍스트가있는 오른쪽에 확인란을 표시하고 싶습니다
어떻게하면 되나요?
스타일을 사용하는 방법을 생각할 수는 없지만 확인란의 텍스트를 아무것도 설정하지 않고 원하는 텍스트로 확인란의 왼쪽에 TextView를 넣을 수 있습니다.
이 질문에 대답하기에는 너무 늦었지만 실제로 목표를 달성 할 수있는 방법이 있습니다. 확인란에 다음 줄을 추가하면됩니다.
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
확인란에 맞춤 드로어 블을 사용할 수도 있습니다.
그리고 radioButton의 경우 :
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
그리고 프로그래밍 방식으로하고 싶다면 :
레이아웃을 정의하고 이름을 RightCheckBox로 지정하고 다음 줄을 복사하십시오.
<?xml version="1.0" encoding="utf-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:text="hello"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"/>
프로그래밍 방식으로 추가 해야하는 경우 CheckBox에 팽창시키고 루트보기에 추가하면됩니다.
CheckBox cb = (CheckBox)((LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.check_right_checkbox,null);
rootView.addView(cb);
넌 할 수있어
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|center"//or "center_vertical" for center text
android:layoutDirection="rtl"
android:text="hello" />
다음 줄이면 충분합니다
android:layoutDirection="rtl"
추가 할 수 android:layoutDirection="rtl"있지만 API 17에서만 사용할 수 있습니다.
이것을 복사하십시오 :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your text:"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
/>
</LinearLayout>
행복한 코딩! :)
확인란 텍스트가 왼쪽에 맞지 않을 수 있습니다
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
일부 장치에서. CheckedTextView 를 대체품으로 사용 하여 문제를 피할 수 있습니다.
<CheckedTextView
...
android:checkMark="@android:drawable/btn_radio" />
이 링크가 도움이 될 것입니다 : 왼쪽 텍스트 정렬, 오른쪽 확인란
checkedTextView를 대신 사용할 수 있습니다.
http://developer.android.com/reference/android/widget/CheckedTextView.html
@The Berga가 제안한 것처럼 추가 할 수는 android:layoutDirection="rtl"있지만 API 17에서만 사용할 수 있습니다.
동적 구현을 위해 여기에 있습니다.
chkBox.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
또한 Hazhir imput 에서이 문제가 필요하면 확인란 xml 구성 android : paddingLeft = "0dp"에 해당 속성을 삽입해야합니다.이 확인란 왼쪽의 빈 공간을 피하기위한 것입니다.
CheckedTextView를 사용하는이 질문에 다른 답변 추가 프로그래밍 방식으로 수행하려는 경우. 확인란에 사용자 정의 이미지를 사용하는 옵션도 있습니다. 단일 뷰에서 수행 가능
final CheckedTextView checkBox = new CheckedTextView(getApplicationContext());
checkBox.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
checkBox.setId(1);
checkBox.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkBox.isChecked()){
checkBox.setChecked(false);
checkBox.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
}else{
checkBox.setChecked(true);
checkBox.setCheckMarkDrawable(android.R.drawable.checkbox_on_background);
}
}
});
checkBox.setTextColor(Color.BLACK);
checkBox.setGravity(Gravity.LEFT);
checkBox.setText("hi");
시작하려는 경우 XML에서-
<CheckedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkMark="@android:drawable/checkbox_off_background"
android:checked="false"
android:text="Hi from xml"/>
다음 링크는 오른쪽 드로어 블을 설정하여 오른쪽에 애니메이션 확인란이있는 여러 표준 Android보기 객체를 렌더링하는 방법을 보여줍니다.
파급 효과를 얻으려면 배경을 설정하십시오.
[오른쪽과 왼쪽에 체크 박스가있는 웹 사이트 링크] [1] http://landenlabs.com/android/uicomponents/uicomponents.html#checkbox
<Button
android:id="@+id/p2Button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent_ripple"
android:drawableRight="@drawable/checkline"
android:gravity="left|center_vertical"
android:text="Button"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="@dimen/buttonTextSize" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/p2Button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent_ripple"
android:drawableRight="@drawable/checkline"
android:gravity="left|center_vertical"
android:text="AppCompatButton"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textSize="@dimen/buttonTextSize" />
<TextView
android:id="@+id/p2TextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent_ripple"
android:drawableRight="@drawable/checkline"
android:gravity="left|center_vertical"
android:hapticFeedbackEnabled="true"
android:text="TextView"
android:textColor="@android:color/white"
android:textSize="@dimen/buttonTextSize" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/p2TextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent_ripple"
android:drawableRight="@drawable/checkline"
android:gravity="left|center_vertical"
android:hapticFeedbackEnabled="true"
android:text="AppCompatTextView"
android:textColor="@android:color/white"
android:textSize="@dimen/buttonTextSize" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/white" />
<CheckBox
android:id="@+id/p2Checkbox1"
android:layout_width="match_parent"
android:layout_height="@dimen/buttonHeight"
android:background="@drawable/transparent_ripple"
android:button="@null"
android:checked="true"
android:drawableRight="@drawable/checkline"
android:gravity="left|center_vertical"
android:text="CheckBox"
android:textColor="@android:color/white"
android:textSize="@dimen/buttonTextSize" />
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/p2Checkbox2"
android:layout_width="match_parent"
android:layout_height="@dimen/buttonHeight"
android:background="@drawable/transparent_ripple"
android:button="@null"
android:checked="true"
android:drawableRight="@drawable/checkline"
android:gravity="left|center_vertical"
android:text="AppCompatCheckBox"
android:textColor="@android:color/white"
android:textSize="@dimen/buttonTextSize" />
<android.support.v7.widget.AppCompatCheckedTextView
android:id="@+id/p2Checkbox3"
android:layout_width="match_parent"
android:layout_height="@dimen/buttonHeight"
android:background="@drawable/transparent_ripple"
android:checkMark="@drawable/checkline"
android:checked="true"
android:gravity="left|center_vertical"
android:text="AppCompatCheckedTextView"
android:textColor="@android:color/white"
android:textSize="@dimen/buttonTextSize" />
<!-- android:checkMark="?android:attr/listChoiceIndicatorMultiple" -->
<CheckedTextView
android:id="@+id/p2Checkbox4"
android:layout_width="match_parent"
android:layout_height="@dimen/buttonHeight"
android:background="@drawable/transparent_ripple"
android:checkMark="@drawable/checkline"
android:checked="true"
android:gravity="left|center_vertical"
android:text="CheckedTextView"
android:textColor="@android:color/white"
android:textSize="@dimen/buttonTextSize" />
<CheckBox
android:id="@+id/p2Checkbox5"
android:layout_width="match_parent"
android:layout_height="@dimen/buttonHeight"
android:background="@drawable/transparent_ripple"
android:checked="true"
android:gravity="center_vertical|end"
android:text="CheckBox"
android:textColor="@android:color/white"
android:textSize="@dimen/buttonTextSize" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/white" />
<ToggleButton
android:id="@+id/p2ToggleButton1"
android:layout_width="match_parent"
android:layout_height="@dimen/buttonHeight"
android:background="@drawable/transparent_ripple"
android:checked="true"
android:drawableRight="@drawable/checkline"
android:gravity="center_vertical|left"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textOff="ToggleButtonOff"
android:textOn="ToggleButtonOn"
android:textSize="@dimen/buttonTextSize" />
<ToggleButton
android:id="@+id/p2ToggleButton2"
android:layout_width="match_parent"
android:layout_height="@dimen/buttonHeight"
android:background="@drawable/transparent_ripple"
android:checked="true"
android:drawableRight="@drawable/btn_check_material_anim"
android:gravity="center_vertical|left"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:textOff="ToggleBtnnAnimOff"
android:textOn="ToggleBtnnAnimOn"
android:textSize="@dimen/buttonTextSize" />
샘플 checkline.xml (드로어 블에서 drawable-v21의 애니메이션 버전에 대한 링크 참조)
샘플 transparent_ripple.xml (drawable-v21)
<!-- Limit ripple to view object, can also use shape such as oval -->
<item android:id="@android:id/mask" android:drawable="@android:color/white" />
<item>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:enterFadeDuration="200"
android:exitFadeDuration="200">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#80c0c000" />
</shape>
</item>
</selector>
</item>
샘플 transparent_ripple.xml (드로어 블에서 사용 가능한 리플 만 강조 표시)
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#80c0c000" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent" />
</shape>
</item>
If it is not mandatory to use a CheckBox you could just use a Switch instead. A Switch shows the text on the left side by default.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/location_permissions"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/black" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="@+id/location_permission_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:onClick="onLocationPermissionClicked" />
</RelativeLayout>
</LinearLayout>
참고URL : https://stackoverflow.com/questions/3156781/how-to-show-android-checkbox-at-right-side
'Programming' 카테고리의 다른 글
| SD 카드에서 파일을 삭제하는 방법? (0) | 2020.07.01 |
|---|---|
| UIBarButtonItem의 글꼴 변경 (0) | 2020.07.01 |
| ViewPager를 사용하여 Google Maps V2를 조각에 배치하는 방법 (0) | 2020.07.01 |
| 보기가 나타나기 전에 iPhone에서 UITableView의 맨 아래로 스크롤하는 방법 (0) | 2020.07.01 |
| PHP로 파일을 업로드 할 때 $ _FILES가 비어있는 이유는 무엇입니까? (0) | 2020.07.01 |