2017-05-07 35 views
0

对于我的应用程序,我需要有一个微调对齐其父母的右端。Android - 微调不能正确对齐到家长的末端

这是我的飞旋的xml:

<Spinner 
      android:id="@+id/createsub_cycle_spinner" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/imageView3" 
      android:layout_alignParentEnd="true" 
      android:layout_below="@+id/imageView2" 
      android:layout_marginEnd="10dp" 
      android:textColorHint="@android:color/white" 
      android:textSize="18sp" /> 

看到,alignParentEnd设置为true

不过当我运行应用程序的resut如下:

gap

上的“周刊”右侧的差距不应该存在。它应该对齐到蓝色布局的最后。

我该如何解决?

编辑:

这里是整个布局:

<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" 
app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

<android.support.v7.widget.CardView 
    android:id="@+id/createsub_card" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="10dp"> 


    <ImageView 
     android:id="@+id/createsub_image" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:scaleType="fitCenter" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="20dp" /> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="80dp"> 

     <TextView 
      android:id="@+id/createsub_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 

     <EditText 
      android:id="@+id/createsub_user_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_marginEnd="10dp" 
      android:maxLines="1" 
      android:onClick="onTitleClicked" 
      android:textAlignment="center" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="1px" 
      android:layout_below="@id/createsub_title" 
      android:layout_marginEnd="10dp" 
      android:layout_marginStart="10dp" 
      android:background="@android:color/white" /> 

     <TextView 
      android:id="@+id/createsub_price" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/createsub_title" 
      android:layout_margin="10dp" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 

     <Spinner 
      android:id="@+id/createsub_currency_spinner" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/imageView2" 
      android:dropDownWidth="40dp" 
      android:layout_alignParentEnd="true" 
      android:layout_below="@id/createsub_user_title" 
      android:layout_marginEnd="10dp" /> 

     <EditText 
      android:id="@+id/createsub_user_price" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/imageView2" 
      android:layout_alignTop="@id/createsub_currency_spinner" 
      android:layout_toStartOf="@id/createsub_currency_spinner" 
      android:inputType="numberDecimal" 
      android:maxLines="1" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" 
      android:hint="0.00" 
      android:textColorHint="@android:color/white"/> 


     <ImageView 
      android:id="@+id/imageView2" 
      android:layout_width="match_parent" 
      android:layout_height="1px" 
      android:layout_below="@id/createsub_price" 
      android:layout_marginEnd="10dp" 
      android:layout_marginStart="10dp" 
      android:background="@android:color/white" /> 

     <TextView 
      android:id="@+id/createsub_cycle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/createsub_price" 
      android:layout_margin="10dp" 
      android:text="@string/cycle" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 

     <Spinner 
      android:id="@+id/createsub_cycle_spinner" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/imageView3" 
      android:layout_alignParentEnd="true" 
      android:layout_below="@+id/imageView2" 
      android:layout_marginEnd="10dp" 
      android:textColorHint="@android:color/white" 
      android:textSize="18sp" /> 

     <ImageView 
      android:id="@+id/imageView3" 
      android:layout_width="match_parent" 
      android:layout_height="1px" 
      android:layout_below="@id/createsub_cycle" 
      android:layout_marginEnd="10dp" 
      android:layout_marginStart="10dp" 
      android:background="@android:color/white" /> 

     <TextView 
      android:id="@+id/createsub_firstbill" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/createsub_cycle" 
      android:layout_margin="10dp" 
      android:text="@string/first_bill" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 


     <!--TODO: when clicked has to show datepickerdialog--> 
     <EditText 
      android:id="@+id/createsub_user_firstbill" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/imageView4" 
      android:layout_alignEnd="@+id/imageView4" 
      android:layout_below="@+id/imageView3" 
      android:inputType="date" 
      android:maxLines="1" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 

     <ImageView 
      android:id="@+id/imageView4" 
      android:layout_width="match_parent" 
      android:layout_height="1px" 
      android:layout_below="@id/createsub_firstbill" 
      android:layout_marginEnd="10dp" 
      android:layout_marginStart="10dp" 
      android:background="@android:color/white" /> 

     <TextView 
      android:id="@+id/createsub_duration" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/createsub_firstbill" 
      android:layout_margin="10dp" 
      android:text="@string/duration" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 

     <Spinner 
      android:id="@+id/createsub_duration_selector" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/imageView5" 
      android:layout_alignParentEnd="true" 
      android:layout_below="@+id/imageView4" 
      android:layout_marginEnd="10dp" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 

     <ImageView 
      android:id="@+id/imageView5" 
      android:layout_width="match_parent" 
      android:layout_height="1px" 
      android:layout_below="@id/createsub_duration" 
      android:layout_marginEnd="10dp" 
      android:layout_marginStart="10dp" 
      android:background="@android:color/white" /> 

     <TextView 
      android:id="@+id/createsub_remindme" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/createsub_duration" 
      android:layout_margin="10dp" 
      android:text="@string/remind_me" 
      android:textColor="@android:color/white" 
      android:textSize="18sp" /> 

     <Spinner 
      android:id="@+id/createsub_reminder_selector" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignEnd="@+id/createsub_user_firstbill" 
      android:layout_below="@+id/imageView5" 
      android:textColorHint="@android:color/white" 
      android:textSize="18sp" /> 


    </RelativeLayout> 
</android.support.v7.widget.CardView> 

回答

1

这里有两件事情可以尝试:

  1. 我注意到,你是硬编码到android:dropDownWidth40dp。 “每周”文本的长度不一定涵盖40dp。尝试删除该属性。

  2. 尝试设置微调的背景为null可删除的空间用于将插入符

    <Spinner 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@null"/> 
    
+1

感谢您的帮助,它是部分它。另一件事是,微调是基于一个数组,并在该数组中有比“每周”更长的字符串,所以他为他们保留空间。我通过在我的'spinner_item.xml'中添加'android:textAlignment =“viewEnd”'来解决它,将文本对齐到最后,从而消除了差距。 – Daniele

0

删除此

android:layout_marginEnd="10dp"

在cardview标签删除此

android:layout_margin="10dp";

+0

感谢您的回答。删除它后,它将10dp移动到右侧但不到布局的最后。 – Daniele

+0

发布整个布局, –

+0

请查看更新后的问题。我已经添加了整个布局。这是相当长的 – Daniele