2016-02-27 2 views
2

Я использую кок делать пользователи могут выбрать свой возраст, который выглядит следующим образом:Android укоротить вращатель ширина содержимого

enter image description here

Раскрывающийся стрелка в настоящее время слишком далеко вправо. Как установить его так, чтобы ширина счетчика была только такой же короткой, как и для содержимого элементов прядильщика?

Код для секции вращателя макета:

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.4" 
      android:text="Age:" /> 

     <Spinner 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/input_age_spinner" 
      android:layout_weight="0.6" /> 

    </LinearLayout> 

Я попытался установить ширину макета вращатель wrap_content но не достичь многого. И я попытался установить вращатель layout_weight на 0,2, что делает его узким, но в этом случае он больше не слева выравнивается

ответ

0

Попробуйте так:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="Age:" /> 

    <Spinner 
     android:id="@+id/input_age_spinner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" /> 
</RelativeLayout> 

(OR)

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Age:" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:orientation="horizontal" > 

     <Spinner 
      android:id="@+id/spinner2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" /> 
    </LinearLayout> 
</LinearLayout> 
+0

есть нет способа сделать это с помощью linearlayout? – Simon

+0

@Simon, Отредактировал мой ответ, но лучше использовать относительный макет, как первый. поскольку вторая - сложная компоновка. – Srikanth

+0

Поместите пробел между текстовым видом и счетчиком при использовании LinearLayout. Дайте ему вес 1, а текст и счетчик весом 0 – Helix

0
<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      android:text="Age:" /> 

     <Space 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 

     <Spinner 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/input_age_spinner" 
      android:layout_weight="0" /> 
</LinearLayout> 
0

попробовать это ..

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <TextView 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" 
     android:text="Age:" /> 

    <Spinner 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="50dp" 
     android:id="@+id/input_age_spinner" /> 

</LinearLayout> 
Смежные вопросы