我要定製一個複選框,以顯示2種不同的狀態,同時檢查,我現在用的是以下2個圖像:的Android定製複選框選擇問題
我的自定義選擇器被定義爲如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/favourite_normal" android:state_checked="false"/>
<item android:drawable="@drawable/favourite_choose" android:state_checked="true"/>
<item android:drawable="@drawable/favourite_normal"/>
但事情是我沒有得到正確的結果,因爲在圖像不正確填充我的複選框視圖,如果我改變複選框的高度和寬度,我必須做的調整。結果我得到這樣的:
完整的佈局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="74dp"
android:background="@drawable/bottom_bav_btn">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="80dp"
android:layout_height="match_parent"
android:id="@+id/linearLayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/jokeListViewBackButton"
android:src="@drawable/back_screen_button_normal"
android:layout_margin="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/linearLayout"
android:layout_toLeftOf="@+id/linearLayout2"
android:layout_toStartOf="@+id/linearLayout2"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="37dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/jokeTitleTextView"
android:gravity="center_vertical|center_horizontal"
android:textColor="@color/fontWhiteColor" />
<TextView
android:layout_width="fill_parent"
android:layout_height="37dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="0/0"
android:id="@+id/jokeCountTxt"
android:gravity="center_vertical|center_horizontal"
android:textColor="@color/fontWhiteColor" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/linearLayout2"
android:gravity="center_vertical|center_horizontal">
<CheckBox
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/checkBox"
android:button="@drawable/custom_favourite_selector"
android:gravity="center_vertical|center_horizontal"
android:checked="false" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:weightSum="1"
android:background="@color/listViewBody"
android:layout_weight="0.71">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/scrollView" >
<com.gravityapps.framework.Utils.CustomTextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text=""
android:id="@+id/jokeTextView"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textSize="25dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp" />
</ScrollView>
</LinearLayout>
<LinearLayout android:id="@+id/navbar"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bottom_nav_back"
android:id="@+id/prevButtonLayout"
android:clickable="true">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView2"
android:background="@drawable/previous_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bottom_nav_back"
android:id="@+id/randPrevButtonLayout"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView3"
android:background="@drawable/reverse_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bottom_nav_back"
android:id="@+id/linearLayout5"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView4"
android:background="@drawable/copy_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bottom_nav_back"
android:id="@+id/linearLayout6"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView7"
android:background="@drawable/share_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bottom_nav_back"
android:id="@+id/randNextButtonLayout"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView5"
android:background="@drawable/forward_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:layout_weight="1"
android:background="@drawable/bottom_nav_back"
android:id="@+id/nextButtonLayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView6"
android:background="@drawable/next_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
我不知道爲什麼我得到這個結果。任何幫助,將不勝感激。謝謝
爲什麼**那可怕的佈局嵌套**?每個視圖一個佈局?您應該知道嵌套佈局**對演出**有負面影響。 –
感謝您的建議,我在實際開發的最後階段對視圖進行了優化和改進,並不確定它是否是正確的事情。 – aaa111
什麼是你的圖像分辨率? –