2015-04-07 2 views
0

Я пытаюсь создать пользовательский интерфейс, который на данный момент использует LinearLayout и их вложение.Альтернативы для макета, который зависит от веса LinearLayout

Это более или менее то, что я пытаюсь выполнить.

+----------------------------------+ |Overlay Text | | | | | | | | | | | | IMAGE | | | | | | | | | | | | | +----------------------------------+ |Overlay Text |Overlay Text | | | | | | | | | IMAGE | | | | | | | | | | | IMAGE +-----------------+ | | | | | | | | | | | BUTTON | | | | | | | +----------------+-----------------+

Основная проблема заключается в том, что используется один и то centerCrop свойство, поэтому контейнер панель имеет фиксированный размер.

Мне удалось получить эту работу, но я прочитал, что производительность может стать хитом с несколькими вложенными LinearLayouts из-за перерасчета беспорядков вложенных представлений. Однако я не видел другого способа сделать это.

Вот мой xml, если вы хотите взглянуть. Любая помощь будет большой.

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/mainOuterLayout"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:id="@+id/shirtRelativeLayout"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/shirtImageView" 
      android:layout_gravity="center_horizontal" 
      android:src="@drawable/shirt_red" 
      android:adjustViewBounds="true" 
      android:layout_weight="1" 
      android:scaleType="centerCrop" /> 

     <TextView 
      android:text="IF THIS" 
      android:id="@+id/shirtTextView" 
      style="@style/overlayTextView" /> 

    </RelativeLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:id="@+id/bottomLinearLayout" 
     android:layout_weight="1"> 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:id="@+id/pantsRelativeLayout" 
      android:layout_weight="1"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/pantsImageView" 
       android:src="@drawable/blue_pants" 
       android:adjustViewBounds="true" 
       android:scaleType="centerCrop" /> 
      <TextView 
       android:text="WEAR THIS" 
       android:id="@+id/pantsTextView" 
       style="@style/overlayTextView" /> 
     </RelativeLayout> 

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:id="@+id/bottomRightLinearLayout" 
      android:layout_weight="1"> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:id="@+id/shoesRelativeLayout" 
       android:layout_weight="1"> 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:id="@+id/shoesImageView" 
        android:src="@drawable/shoes" 
        android:scaleType="centerCrop" 
        android:adjustViewBounds="true" /> 

       <TextView 
        android:text="AND THAT" 
        android:id="@+id/shoesTextView" 
        style="@style/overlayTextView" /> 

      </RelativeLayout> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:text="Roll Again" 
       android:id="@+id/reloadOutfitButton" 
       android:background="#b19636" 
       android:textSize="16sp" 
       android:textColor="@android:color/white" 
       android:layout_weight="1" /> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 

+1

Ваше мнение дерево не так глубоко. Вы должны быть в порядке, если вы не нацеливаете на очень старые устройства, работающие на 2. * – Naveed

+0

, какова ваша конкретная проблема? –

ответ

1

Хорошие новости теперь мы приобретенная альтернативу для вложенного веса LinearLayout собственности от андроида percent support Library

Demo HERE !

GitHub Project HERE !

Рассмотрите этот простой макет.

<android.support.percent.PercentRelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView 
     android:id="@+id/fifty_huntv" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:background="#ff7acfff" 
     android:text="20% - 50%" 
     android:textColor="@android:color/white" 
     app:layout_heightPercent="20%" 
     app:layout_widthPercent="50%" /> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_toRightOf="@id/fifty_huntv" 
     android:background="#ffff5566" 
     android:text="80%-50%" 
     app:layout_heightPercent="80%" 
     app:layout_widthPercent="50%" 
     /> 

</android.support.percent.PercentRelativeLayout> 

Некоторые комплекс плитки макет мы можем создать, являются:

tile layout

Смежные вопросы