如何在android微调器中对齐文本?

如何在android微调器中对齐文本?,android,spinner,Android,Spinner,我想将微调器中的文本向左对齐,但如何实现这一点需要帮助 这是我的代码和屏幕截图 <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:background="@drawable/roundshape" >

我想将微调器中的文本向左对齐,但如何实现这一点需要帮助

这是我的代码和屏幕截图

 <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/roundshape" >

        <!-- Lable Area -->

        <TableRow
            android:id="@+id/tblRwspnLbl"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"           
            android:gravity="center" 
            android:padding="1dip">

            <TextView
                android:id="@+id/lblCust"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:text="@string/lblCust"
                android:textSize="14sp"
                android:textStyle="bold" 
                android:gravity="left"/>

            <TextView
                android:id="@+id/lblPros"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:text="@string/lblPros"
                android:textSize="14sp"
                android:textStyle="bold" />
        </TableRow>

        <!-- Spinner Area -->

        <TableRow
            android:id="@+id/tblRwspn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="1dip"                
            android:gravity="center" >

            <Spinner
                android:id="@+id/spnAECust"
                android:layout_width="75dp"
                android:layout_height="35dp"
                android:fontFamily="verdana,arial,helvetica"
                android:hint="@string/SelectCust"
                android:textSize="14sp" 
                android:layout_gravity="left"/>

            <Spinner
                android:id="@+id/spnAEProspect"
                android:layout_width="75dp"
                android:layout_height="35dp"
                android:fontFamily="verdana,arial,helvetica"
                android:hint="@string/SelectProspect"
                android:textSize="14sp" />
        </TableRow>

        <!-- Text Area -->

这是我的屏幕,红点是我要删除的空间,所以我的所有标签和微调器都将在同一条对齐的线上


只需从Spinner TableRow中删除android:padding=“1dip”,然后再试一次我不确定,请再试一次

编辑: 您必须在此处使用自定义视图来对齐微调器值。创建一个类似answer创建的自定义视图,并将
android:gravity'添加到文本视图中作为
right`

并使用将CustomView设置为适配器

adapter.setDropDownViewResource(android.R.layout.your_custom_created_view);

我认为您应该使用自定义
ArrayAdapter
TextView
并根据需要使用TextView属性

例如:

MyAdapter.java

    public class MyAdapter extends ArrayAdapter {
Context context;
    public MyAdapter(Context context, int resource) {
        super(context, resource);
        this.context=context;
        // TODO Auto-generated constructor stub
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(R.layout.mylayout, parent,false);
        TextView textView=(TextView)view.findViewById(R.id.text);

        return view;
    }
}
mylayout.xml

 <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <TextView
         android:id="@+id/text"
         android:layout_width="match-parent"
         android:layout_height="wrap_content"
         android:text="@string/lblPros"
         android:textSize="14sp"
         android:gravity="right"
         android:textStyle="bold" />
</LinearLayout>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/text_for_spinner"
    style="?android:attr/spinnerItemStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawablePadding="10dp"
    android:drawableRight="@drawable/arrow"
    android:gravity="center"
    android:textColor="@android:color/white" >

</TextView>

试试这个:-

使用android:layout\u span=“1”。如果需要,则为第一行提供左边距

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/roundshape" >

    <!-- Lable Area -->

    <TableRow
        android:id="@+id/tblRwspnLbl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"           
        android:gravity="center" ">

        <TextView
            android:id="@+id/lblCust"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/lblCust"
            android:layout_span="1"
            android:textSize="14sp"
            android:textStyle="bold" 
            android:gravity="left"/>

        <TextView
            android:id="@+id/lblPros"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="1"
            android:text="@string/lblPros"
            android:textSize="14sp"
            android:textStyle="bold" />
    </TableRow>

    <!-- Spinner Area -->

    <TableRow
        android:id="@+id/tblRwspn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"             
        android:gravity="center" >

        <Spinner
            android:id="@+id/spnAECust"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="1"
            android:fontFamily="verdana,arial,helvetica"
            android:hint="@string/SelectCust"
            android:textSize="14sp" 
            android:layout_gravity="left"/>

        <Spinner
            android:id="@+id/spnAEProspect"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="1"
            android:fontFamily="verdana,arial,helvetica"
            android:hint="@string/SelectProspect"
            android:textSize="14sp" />
    </TableRow>

    <!-- Text Area -->


这是可能有用的示例代码

<Spinner
                    android:id="@+id/spinner1"
                    style="?android:attr/spinnerStyle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:layout_marginBottom="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/dropdown"
                    android:dropDownVerticalOffset="1dp"
                    android:focusable="false"
                    android:spinnerMode="dropdown" />

谢谢你们给了我所有可能的答案,这是我得到的解决方案

 android:layout_width="75dp"

  android:layout_height="35dp"

  android:layout_marginLeft="5dp"

  android:paddingLeft="5dp"

  android:gravity="left"

其用于标签客户和微调器之间的距离,不用于右侧对齐
 android:layout_width="75dp"

  android:layout_height="35dp"

  android:layout_marginLeft="5dp"

  android:paddingLeft="5dp"

  android:gravity="left"