2016-12-30 3 views
0

У меня есть код, как это:Как перемещать прядильщик в LinearLayout вправо?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:layout_marginLeft="20dp" 
android:layout_marginTop="20dp" 
android:layout_marginRight="20dp" 
> 

<LinearLayout 
    android:id="@+id/relativeLayoutforPRICE" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/textView$_points_to_win" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Points to win" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <Spinner 
     android:id="@+id/spinner$_points_to_win" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     /> 

</LinearLayout> 

В настоящее время это выглядит следующим образом:

enter image description here

Я хотел бы перейти Spinner к правой стороне LinearLayout. Я пытался использовать:

android:gravity="right" 

и

android:gravity="end" 

и

android:layout_gravity="right" 

и

android:layout_gravity="end" 

, но это не помогло. Есть ли другой способ переместить его вправо? Что еще важно, я хочу сохранить родительский макет как линейный (ориентированный по вертикали) и текущий макет как линейный (ориентированный по горизонтали).

+1

Вы можете использовать 'layout_weight = "1"' в 'TextView' –

+0

Используйте FrameLayout вместо этого, если вы установите' андроида: layout_gravity = "право" 'для Spinner – withparadox2

+0

@ChiragSavsani, что вы сказали, ооочень интересно ! Тем не менее, я хотел бы знать, есть ли способ удержать этот счетчик как можно меньше и только сдвинуть его вправо. – Tomas

ответ

1

Я предлагаю использовать RelativeLayout эту логику:

<RelativeLayout 
    android:id="@+id/relativeLayoutforPRICE" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/textView$_points_to_win" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Points to win" 
     android:layout_alignParentLeft="true" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <Spinner 
     android:id="@+id/spinner$_points_to_win" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true"/> 

</RelativeLayout> 

родительским выравнивание свойства (т.е. layout_alignParentLeft, layout_alignParentRight), вы можете разместить компоненты предпочитаемым месту

1

Эй этот код.

<LinearLayout 
    android:id="@+id/relativeLayoutforPRICE" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="2"> 

    <TextView 
     android:id="@+id/textView$_points_to_win" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Points to win" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <Spinner 
     android:id="@+id/spinner$_points_to_win" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 

</LinearLayout> 

Надеюсь эта помощь.Хорошая кодировка.

1

используйте относительный макет вместо линейной компоновки

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:layout_marginLeft="20dp" 
android:layout_marginTop="20dp" 
android:layout_marginRight="20dp" 
> 

<RelativeLayout 
    android:id="@+id/relativeLayoutforPRICE" 
    android:layout_width="match_parent" 
    android:layout_gravity="right" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/textView$_points_to_win" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Points to win" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <Spinner 
     android:id="@+id/spinner$_points_to_win" 
     android:layout_alignParentRight="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     /> 

</RelativeLayout> 
</LinearLayout> 
1

Комплект layout_width Измельчитель и комплект layout_weight Текс tView.

<LinearLayout 
    android:id="@+id/relativeLayoutforPRICE" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/textView$_points_to_win" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Points to win" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <Spinner 
     android:id="@+id/spinner$_points_to_win" 
     android:layout_width="50dp" 
     android:layout_height="wrap_content"/> 

</LinearLayout> 
+0

Примите этот ответ, если это сработает для вас. –

1

попробуйте этот код, я немного обновил его.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_marginLeft="20dp" 
    android:layout_marginTop="20dp" 
    android:layout_marginRight="20dp" 
    > 

    <LinearLayout 
     android:id="@+id/relativeLayoutforPRICE" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/textView$_points_to_win" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Points to win" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <Spinner 
      android:id="@+id/spinner$_points_to_win" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      /> 

    </LinearLayout> 

здесь скриншот это хорошо работает как

http://screencast.com/t/kD5y6PlVi

+0

Спасибо @Tomas fir upvote –

0

Изменить свой LinearLayout на следующее:

<LinearLayout 
     android:id="@+id/relativeLayoutforPRICE" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true"> 
1

Просто channge следующие изменения в коде.

В TextView

layout_width="0dp" 
layout_weight="1" 

См код.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:layout_marginLeft="20dp" 
android:layout_marginTop="20dp" 
android:layout_marginRight="20dp"> 

<LinearLayout 
    android:id="@+id/relativeLayoutforPRICE" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/textView$_points_to_win" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     layout_weight="1" 
     android:text="Points to win" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <Spinner 
     android:id="@+id/spinner$_points_to_win" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

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