-3

我如何对齐spinner以在所有屏幕上显示相等的宽度?在我的代码spinner中在不同的屏幕上显示不同的宽度我该怎么办?我给了固定长度

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

edittext并且spinnerspinner在不同的屏幕中显示不同的宽度我该如何解决这个问题?我这是我的屏幕图像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>

4

2 回答 2

0

这不是你的错,默认背景Spinner有这种图像(它周围的透明填充)。您可以通过设置来查看自己android:background="#ffffff",这样做会从' 的侧面Spinner移除填充,您的问题会解决,但您会松开箭头。我建议您创建自己的for (因为您正在更改 other 的背景),否则默认背景对于不同的操作系统版本是不同的,并且您的实现似乎会失败。SpinnerSpinnerdrawableSpinnerView

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>

再次调整您的引用,以防您复制粘贴我的代码。

于 2013-02-25T09:47:58.163 回答
0

实际上你的代码是对的。它看起来与 EditText 框的大小不同,因为您在微调器中使用了默认背景。

如果您更改了其背景颜色或图像,例如

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

你可以改变它的背景图片

android:background="@drawable/spinnerDropDownBackground" 

并确保图像是 9 路径,这样它就不会在大屏幕上浆糊

如何为微调器创建 9 个补丁?

你会发现你的代码是正确的。

如果你想使用默认背景,你必须改变你的代码

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

希望这会有所帮助

于 2013-02-25T09:38:05.710 回答