Android:4.2.2 及以下版本具有内在边界的复合可绘制对象
Android: Compound Drawables With Intrinsic Bounds on 4.2.2 and below
我尝试像这样使用带有左侧复合可绘制对象的复选框:
holder.selCategoryCheckBox.setCompoundDrawablesWithIntrinsicBounds(imageResource, 0, 0, 0);
xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<CheckBox
android:id="@+id/category_sel_checkbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/categorySelectionOptions"
android:layout_toStartOf="@+id/categorySelectionOptions"
android:drawablePadding="@dimen/more_than_big_padding"
android:paddingLeft="@dimen/big_padding"
android:paddingTop="@dimen/big_padding"
android:paddingBottom="@dimen/big_padding"
android:singleLine="true"
android:textSize="18sp"
android:layout_marginLeft="@dimen/five_margin"
android:layout_marginStart="@dimen/five_margin"/>
<ImageView
android:id="@+id/categorySelectionOptions"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="@dimen/main_middle_margin"
android:layout_marginStart="@dimen/main_middle_margin"
android:background="@drawable/row_selector_list_dots"
android:clickable="true"
android:src="@drawable/ic_action_drawer_dots"
android:contentDescription="@string/image"
android:layout_centerVertical="true" />
On Android 4.3 Jelly Bean 和 Up 运行良好:
但在 Android 4.2 Jelly Bean 及以下间距被打破:
一些想法,有什么问题吗?
临时解决方法:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:id="@+id/category_sel_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="@dimen/larger_margin"
android:layout_marginStart="@dimen/larger_margin"/>
<TextView
android:id="@+id/category_sel_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/middle_margin"
android:layout_marginStart="@dimen/middle_margin"
android:layout_marginRight="@dimen/large_margin"
android:layout_marginEnd="@dimen/large_margin"
android:singleLine="true"
android:textSize="18sp"/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="@+id/category_sel_checkbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/five_margin"
android:layout_marginStart="@dimen/five_margin"/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/categorySelectionOptions"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/main_middle_margin"
android:layout_marginStart="@dimen/main_middle_margin"
android:background="@drawable/row_selector_list_dots"
android:layout_gravity="end"
android:clickable="true"
android:src="@drawable/ic_action_drawer_dots"
android:contentDescription="@string/image" />
</FrameLayout>
我尝试像这样使用带有左侧复合可绘制对象的复选框:
holder.selCategoryCheckBox.setCompoundDrawablesWithIntrinsicBounds(imageResource, 0, 0, 0);
xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<CheckBox
android:id="@+id/category_sel_checkbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/categorySelectionOptions"
android:layout_toStartOf="@+id/categorySelectionOptions"
android:drawablePadding="@dimen/more_than_big_padding"
android:paddingLeft="@dimen/big_padding"
android:paddingTop="@dimen/big_padding"
android:paddingBottom="@dimen/big_padding"
android:singleLine="true"
android:textSize="18sp"
android:layout_marginLeft="@dimen/five_margin"
android:layout_marginStart="@dimen/five_margin"/>
<ImageView
android:id="@+id/categorySelectionOptions"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="@dimen/main_middle_margin"
android:layout_marginStart="@dimen/main_middle_margin"
android:background="@drawable/row_selector_list_dots"
android:clickable="true"
android:src="@drawable/ic_action_drawer_dots"
android:contentDescription="@string/image"
android:layout_centerVertical="true" />
On Android 4.3 Jelly Bean 和 Up 运行良好:
但在 Android 4.2 Jelly Bean 及以下间距被打破:
一些想法,有什么问题吗?
临时解决方法:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:id="@+id/category_sel_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="@dimen/larger_margin"
android:layout_marginStart="@dimen/larger_margin"/>
<TextView
android:id="@+id/category_sel_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/middle_margin"
android:layout_marginStart="@dimen/middle_margin"
android:layout_marginRight="@dimen/large_margin"
android:layout_marginEnd="@dimen/large_margin"
android:singleLine="true"
android:textSize="18sp"/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="@+id/category_sel_checkbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/five_margin"
android:layout_marginStart="@dimen/five_margin"/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/categorySelectionOptions"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/main_middle_margin"
android:layout_marginStart="@dimen/main_middle_margin"
android:background="@drawable/row_selector_list_dots"
android:layout_gravity="end"
android:clickable="true"
android:src="@drawable/ic_action_drawer_dots"
android:contentDescription="@string/image" />
</FrameLayout>