2016-10-26 11 views
0

Моя цель состоит в том, чтобы иметь три вида в одной строке, независимо от того, насколько большой дисплей устройства. Также я хочу, чтобы у этих трех представлений было такое же пространство между ними, чтобы оно выглядело симметричным. Возможны ли эти две вещи, и если да, то как? Заранее спасибо!Как я могу сделать три представления всегда в одной строке, а также всегда иметь такое же пространство между ними?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    tools:context="com.juliandrach.eatfit.MainActivity"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"> 

     <ImageView 
      android:layout_width="48dp" 
      android:layout_height="48dp" 
      android:background="@drawable/profilbild" 
      android:layout_margin="10dp" 
      /> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="Ernährungspläne" 
      android:textAllCaps="true" 
      android:textSize="21sp" 
      android:layout_marginTop="15dp" 
      android:textColor="@android:color/black" 
      android:layout_weight="2" 
      /> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="Shop" 
      android:textAllCaps="true" 
      android:textSize="25sp" 
      android:textColor="@android:color/black" 
      android:layout_weight="1" 
      android:layout_marginTop="15dp"/> 
    </LinearLayout> 
    (...) 
+0

использование weightSum в LinearLayout и добавить layout_weight в трех ваших взглядов. Чтобы узнать больше, проверьте эту ссылку http://stackoverflow.com/questions/7452741/what-is-androidweightsum-in-android-and-how-does-it-work- – YLS

ответ

0

Final Заканчивать

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    tools:context="com.juliandrach.eatfit.MainActivity"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="3" 
    android:orientation="horizontal" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@mipmap/ic_launcher" 
     android:layout_weight="0" 
     /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Ernährungspläne" 
     android:textAllCaps="true" 
     android:textSize="21sp" 
     android:layout_marginTop="15dp" 
     android:layout_marginLeft="15dp" 
     android:textColor="@android:color/black" 
     android:layout_weight="1" 
     android:id="@+id/textView" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Shop" 
     android:textAllCaps="true" 
     android:textSize="21sp" 
     android:layout_marginTop="15dp" 
     android:layout_marginLeft="15dp" 
     android:textColor="@android:color/black" 
     android:layout_weight="1" 
     android:id="@+id/textView1" /> 

</LinearLayout> 
</RelativeLayout> 

сдвинуты влево

+0

Спасибо, что вам хорошо! Можно ли сдвинуть все немного вправо, так что на стороне не осталось слишком много места, но при этом остается одинаковое пространство между видами? – Julian

+0

проверить сейчас .. – nzala

+0

красивый, спасибо! – Julian

0

Привет попробуйте этот код надеюсь, что это может помочь вам ..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.juliandrach.eatfit.MainActivity"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:weightSum="1"> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="48dp" 
     android:layout_margin="10dp" 
     android:layout_weight=".33" 
     android:background="@drawable/profilbild" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="2dp" 
     android:layout_marginTop="15dp" 
     android:layout_weight=".33" 
     android:text="Ernährungspläne" 
     android:textAllCaps="true" 
     android:textColor="@android:color/black" 
     android:textSize="21sp" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="2dp" 
     android:layout_marginTop="15dp" 
     android:layout_weight=".33" 
     android:text="Shop" 
     android:textAllCaps="true" 
     android:textColor="@android:color/black" 
     android:textSize="25sp" /> 
</LinearLayout></RelativeLayout> 
+0

Спасибо! Проблема с этим кодом заключается в том, что взгляды становятся непропорциональными. Например, imageView растягивается, и первый textView сокращается и записывается в две строки:/ – Julian

0

вы должны использовать wightsum как 3

каждый внутренний вид, как LayoutWidth как 1 будет работать для вас

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="3" 
     android:orientation="horizontal" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:background="@mipmap/ic_launcher" 
      android:layout_weight="1" 
      android:layout_margin="10dp" 
      /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="abc" 
      android:textAllCaps="true" 
      android:textSize="21sp" 
      android:layout_marginTop="15dp" 
      android:textColor="@android:color/black" 
      android:layout_weight="1" 
      android:id="@+id/textView" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="abc" 
      android:textAllCaps="true" 
      android:textSize="21sp" 
      android:layout_marginTop="15dp" 
      android:textColor="@android:color/black" 
      android:layout_weight="1" 
      android:id="@+id/textView1" /> 
    </LinearLayout> 

</RelativeLayout> 

, пожалуйста, дайте мне знать, если он не работает для вас.

+0

Эй, спасибо! Проблема с этим кодом заключается в том, что представления снова непрофессиональны. Возможно ли, что изображениеView остается пропорциональным (например, 48/48), и два текстовых окна занимают столько места, сколько нужно от остальных, не переходя ко второй строке? Когда я использую ваш код и помещаю его в «Ernährungspläne» в первом текстовом элементе, он будет использовать две строки. – Julian

+0

они должны принять это, потому что вам нужно постоянное пространство между тремя элементами. вы можете иметь эллипсы и сделать singleLine = true –