2013-02-25 39 views
-3

如何對齊spinner以在所有屏幕中顯示寬度相等?在我的代碼spinner中顯示不同的寬度在不同的屏幕上我該怎麼做?我已經給固定長度如何對齊旋轉編輯文本的寬度相等

android:layout_marginRight="45dp" 
android:layout_marginLeft="45dp" 
edittextspinnerspinner

顯示不同勢屏幕不同勢寬度如何解決這個問題?我這是我的屏幕圖像http://imgur.com/RtWNgNI 以下是我的完整屏幕源代碼。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#000000" 
android:orientation="vertical" 
android:weightSum="6" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_marginTop="55dp" 
    android:layout_weight="0.5" 
    android:orientation="horizontal" 
    android:weightSum="1" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:paddingBottom="10dp" 
     android:src="@drawable/agappbg" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="15dp" 
    android:layout_weight="0.2" 
    android:orientation="horizontal" 
    android:weightSum="1" > 

    <EditText 
     android:id="@+id/txtMobileNo" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="45dp" 
     android:layout_marginRight="45dp" 
     android:layout_weight="1" 
     android:background="#ffffff" 
     android:gravity="left" 
     android:hint="@string/MobileNo" 
     android:singleLine="true" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.2" 
    android:orientation="horizontal" 
    android:weightSum="1" > 

    <EditText 
     android:id="@+id/txtPinNo" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="45dp" 
     android:layout_marginRight="45dp" 
     android:layout_weight="1" 
     android:background="#ffffff" 
     android:gravity="left" 
     android:hint="@string/PinNo" 
     android:inputType="textPassword" 
     android:singleLine="true" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.1" 
    android:orientation="horizontal" 
    android:weightSum="1" > 

    <Spinner 
     android:id="@+id/lgnspinner" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="-17dp" 
     android:layout_marginLeft="45dp" 
     android:layout_marginRight="45dp" 
     android:layout_marginTop="-15dp" 
     android:layout_weight="1" 
     android:paddingBottom="12dp" 
     android:paddingTop="12dp" 
     android:prompt="@string/network_prompt" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:layout_weight="0" 
    android:orientation="horizontal" 
    android:weightSum="4" > 

    <Button 
     android:id="@+id/btnLogin" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="45dp" 
     android:layout_weight="1" 
     android:background="@drawable/curvedplanebutton_small" 
     android:text="Login" 
     android:textColor="@drawable/button_text_color" /> 
</LinearLayout> 

+0

圖片鏈接已損壞請重新檢查它 – 2013-02-25 09:25:43

+0

http://imgur.com/RtWNgNI chk這 – 2013-02-25 09:26:42

+0

是不是壞了我只是給半屏圖像 – 2013-02-25 09:27:07

回答

0

其實你做了正確的代碼。它看起來像與EditText框不一樣的大小,因爲你在微調框中使用了默認背景。

如果你改變了它的背景顏色或圖片類似

android:background="@android:color/darker_gray" 

,你可以改變它的背景圖片

android:background="@drawable/spinnerDropDownBackground" 

並確保圖像9路徑,使其在大屏幕沒有漿洗

How to create 9 patch for spinner ?

你會發現你的代碼是正確的。

如果你想使用你必須改變你的代碼

android:layout_marginRight="40dp" 
android:layout_marginLeft="40dp" 

希望默認的背景,這將有助於

+1

如果我給機器人:layout_marginRight =」 40dp」 機器人:layout_marginLeft =‘40dp’是不是在不同勢sceen相同尺寸 – 2013-02-25 09:41:06

+0

如果我給任何顏色微調器不顯示正確的下拉箭頭,你想它一樣大小的EditText框 – 2013-02-25 09:45:01

+0

或所有的屏幕大小固定? – 2013-02-25 09:45:15

0

它不是Spinner你的錯,默認背景有這種圖像的(透明在它周圍填充)。你可以在Spinner上設置android:background="#ffffff",這樣做會從Spinner的邊上移除填充,你的問題將解決,但你會鬆動Spinner箭頭。我建議你爲Spinner創建自己的drawable(因爲你正在改變其他View的背景),否則對於不同的操作系統版本,默認背景是不同的,你的實現看起來會破壞。

此外,您正在使用這麼多LinerLayout s這個簡單的佈局。考慮這個:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#000000" 
android:orientation="vertical" 
android:weightSum="100" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_gravity="center_horizontal" 
    android:layout_weight="30" 
    android:paddingBottom="10dp" 
    android:src="@drawable/ic_launcher" /> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="70" 
    android:orientation="vertical" 
    android:padding="16dp" > 

    <EditText 
     android:id="@+id/txtMobileNo" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:layout_marginBottom="4dp" 
     android:background="#ffffff" 
     android:gravity="center_vertical" 
     android:hint="MobileNo" 
     android:padding="4dp" 
     android:singleLine="true" /> 

    <EditText 
     android:id="@+id/txtPinNo" 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:layout_marginBottom="4dp" 
     android:background="#ffffff" 
     android:gravity="center_vertical" 
     android:hint="Pin no" 
     android:inputType="textPassword" 
     android:padding="4dp" 
     android:singleLine="true" /> 

    <Spinner 
     android:id="@+id/lgnspinner" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="4dp" 
     android:background="#ffffff" /> 

    <Button 
     android:id="@+id/btnLogin" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:text="Login" /> 
</LinearLayout> 

</LinearLayout> 

再次調整您的引用,以防複製粘貼我的代碼。

+0

我建議你從以下網站生成你的主題,然後使用它並調整你的佈局。一旦調整,它不會再次破壞,因爲您的背景對於不同的操作系統版本將是相同的。 http://android-holo-colors.com/ – 2013-02-25 09:50:41

+0

再次相同的錯誤烏爾微調不顯示的下拉箭頭 – 2013-02-25 09:51:43

+0

當然,因爲你不再使用的背景,箭頭,你將失去方向,而不是現在使用的是簡單的顏色值。這就是爲什麼我上面評論,並建議你創建自己的具有箭頭的「Spinner」背景。這樣你的'Spinner'不會在不同的Android操作系統版本上改變形狀。 – 2013-02-25 09:56:27