2015-02-24 63 views
2

我附加了屏幕捕獲與兩個19個21模擬器運行: enter image description here的EditText填充屬性不起作用相同的API 19和21

左邊的一個是Android的19和上一個正如您所看到的,基於API 19的模擬器不考慮填充屬性。同樣的事情發生在4.4.x設備上,所以它不僅僅是一個模擬器問題。

這是我使用的這個活動的.XML代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.birsan.cardbox.FolderScreen"> 

<ImageView 
    android:id="@+id/magnifying_glass_icon" 
    android:layout_width="20dp" 
    android:layout_height="20dp" 
    android:layout_alignBottom="@+id/search_button" 
    android:layout_alignLeft="@+id/search_folder" 
    android:layout_alignStart="@+id/search_folder" 
    android:layout_marginBottom="2dp" 
    android:layout_marginLeft="9dp" 
    android:layout_marginStart="9dp" 
    android:contentDescription="magnifying glass" 
    android:src="@drawable/ic_menu_search" /> 

<include 
    android:id="@+id/toolbar" 
    layout="@layout/app_bar" /> 


<EditText 
    android:id="@+id/search_folder" 
    android:layout_width="250dp" 
    android:layout_height="30dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginTop="10dp" 
    android:background="@drawable/search_custom_widget" 
    android:focusable="true" 
    android:hint="Search in folders" 
    android:iconifiedByDefault="false" 
    android:paddingLeft="40dp" 
    android:paddingRight="55dp" 
    android:singleLine="true" 
    android:textSize="14sp" 

    android:textStyle="bold" /> 

<Button 
    android:id="@+id/search_button" 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="26dp" 
    android:layout_alignBottom="@+id/search_folder" 
    android:layout_alignEnd="@+id/search_folder" 
    android:layout_alignRight="@+id/search_folder" 
    android:layout_marginBottom="2dp" 
    android:layout_marginRight="2dp" 
    android:background="@color/my_blue" 

    android:text="Go" 
    android:textColor="#fff" 
    android:textSize="10sp" /> 


<com.name.cardbox.SlidingTabLayout 
    android:id="@+id/sliding_tabs" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_below="@+id/app_bar" 
    android:layout_marginTop="40dp" 
    android:background="@color/my_blue" /> 


<android.support.v4.view.ViewPager 
    android:id="@+id/viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/sliding_tabs" 
    android:background="#fff"> 


</android.support.v4.view.ViewPager> 

爲什麼不一致?我錯過了什麼,如何修復它?謝謝。

回答

5

這似乎是API 21中的一個錯誤 - Issue 77982

應該在將來的版本中修復。對於臨時修復,請嘗試動態設置填充。

更新: 1)Actually, the 21 works fine. Is the 19 that doesn't.

的錯誤本身就是 - 「填充工作在21 API及精細較低的Android設備不工作」。這個bug存在於sdk 21中,並且由於您使用sdk 21編譯您的應用程序,所以填充在低級apis中不起作用。

2)searchView.setPadding(40, 0, 55, 0);

這將設置在像素填充,如果你在高denisty的設備上運行它,你不會注意到其中的差別。嘗試設置填充在DP

int paddingLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics()); 
     int paddingRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 55, getResources().getDisplayMetrics()); 
     int paddingTop = editText.getPaddingTop(); 
     int paddingBottom = editText.getPaddingBottom(); 
     editText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); 
+0

感謝您的回覆。其實,21的工作正常。是不是19。我試圖使用兩個:searchView.setPaddingRelative(40,0,55,0);和searchView.setPadding(40,0,55,0);以相同的結果,沒有修復。 – Nactus 2015-02-24 16:45:08

+0

@Nactus檢查更新後的答案。 – 2015-02-24 17:10:08

+0

謝謝阿布舍克五世修正它。 Upvoted並解決。 – Nactus 2015-02-24 17:32:19

0

您現在應該使用android:paddingStart代替android:paddingLeft無論如何,這也修正了這個bug。似乎沒有系統修復。