2017-02-15 62 views
0

我想排列我的看法,但由於CheckBox視圖區域比實際背景大,它似乎是超出比例Android Studio將標準複選框背景置於複選框的左邊框?

下面的圖片展示了我的問題

enter image description here

正如你可以看到它是不是與下面的輸入字段一字排開。 有沒有辦法以將背景推到左邊框?

xmllayout低於

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:background="@drawable/list_item_palegrey_border_bottom" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp"> 

<Space 
    android:layout_width="match_parent" 
    android:layout_height="10dp" 
    android:id="@+id/topSpace"/> 

<android.support.percent.PercentRelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/milageHeader" 
    android:layout_below="@id/topSpace" 
    android:layout_marginBottom="5dp"> 

     <TextView 
      app:layout_widthPercent="40%" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:layout_centerVertical="true" 
      android:id="@+id/milageLabel" 
      android:text="Milersättning:"/> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/milageCheckBox" 
     android:layout_centerVertical="true" 
     app:layout_marginLeftPercent="40%"/> 

</android.support.percent.PercentRelativeLayout> 


<android.support.percent.PercentRelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/milageContent" 
    android:visibility="visible" 
    android:layout_below="@id/milageHeader"> 

    <android.support.percent.PercentRelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/kilometersContainer" 
     android:layout_marginBottom="10dp"> 

     <TextView 
      app:layout_widthPercent="40%" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:id="@+id/kilometersLabel" 
      android:text="Antal körda km:" 
      android:layout_centerVertical="true"/> 

     <EditText 
      app:layout_widthPercent="30%" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:background="@drawable/border_square" 
      android:theme="@style/AppTheme" 
      android:id="@+id/kilometersEditText" 
      android:layout_toRightOf="@+id/kilometersLabel" 
      android:layout_toEndOf="@id/kilometersLabel"/> 

    </android.support.percent.PercentRelativeLayout> 

    <android.support.percent.PercentRelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/fromCityPlaceContainer" 
     android:layout_below="@+id/kilometersContainer" 
     android:layout_marginBottom="10dp"> 

     <TextView 
      app:layout_widthPercent="40%" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:id="@+id/fromCityPlaceLabel" 
      android:text="Från ort/plats:" 
      android:layout_centerVertical="true"/> 

     <EditText 
      app:layout_widthPercent="30%" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:theme="@style/AppTheme" 
      android:background="@drawable/border_square" 
      android:id="@+id/fromCityPlaceEditText" 
      android:layout_toRightOf="@+id/fromCityPlaceLabel" 
      android:layout_toEndOf="@id/fromCityPlaceLabel"/> 

    </android.support.percent.PercentRelativeLayout> 

    <android.support.percent.PercentRelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/toCityPlaceContainer" 
     android:layout_below="@+id/fromCityPlaceContainer"> 

     <TextView 
      app:layout_widthPercent="40%" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:id="@+id/toCityPlaceLabel" 
      android:text="Till ort/plats:" 
      android:layout_centerVertical="true"/> 

     <EditText 
      app:layout_widthPercent="30%" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:id="@+id/toCityPlaceEditText" 
      android:background="@drawable/border_square" 
      android:theme="@style/AppTheme" 
      android:layout_toRightOf="@+id/toCityPlaceLabel" 
      android:layout_toEndOf="@id/toCityPlaceLabel"/> 

    </android.support.percent.PercentRelativeLayout> 

    <android.support.percent.PercentRelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/returnContainer" 
     android:layout_below="@+id/toCityPlaceContainer"> 

     <TextView 
      app:layout_widthPercent="40%" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:id="@+id/returnLabel" 
      android:text="Tur och retur:" 
      android:layout_centerVertical="true"/> 

     <CheckBox 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:id="@+id/returnCheckBix" 
      android:theme="@style/AppTheme" 
      android:layout_toRightOf="@+id/returnLabel" 
      android:layout_toEndOf="@id/returnLabel"/> 

    </android.support.percent.PercentRelativeLayout> 

    <android.support.percent.PercentRelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/purposeContainer" 
     android:layout_below="@+id/returnContainer"> 

     <TextView 
      app:layout_widthPercent="40%" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:id="@+id/purposeLabel" 
      android:text="Syfte:" 
      android:layout_centerVertical="true"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:theme="@style/AppTheme" 
      android:id="@+id/purposeEditText" 
      android:background="@drawable/border_square" 
      android:layout_toRightOf="@+id/purposeLabel" 
      android:layout_toEndOf="@id/purposeLabel"/> 

    </android.support.percent.PercentRelativeLayout> 

</android.support.percent.PercentRelativeLayout> 

<Space 
    android:layout_width="match_parent" 
    android:layout_height="10dp" 
    android:layout_below="@id/milageContent"/> 

+0

你可以發表你的佈局文件 –

+0

@AdityaDesai我更新了帖子,看看 –

+0

試穿複選框 –

回答

0

我加入android:translationX="-7dp"到移動背景的左邊框的CheckBox解決了這個問題。

enter image description here