2013-03-19 5 views
2

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

+-----------------------------------------+ 
|   Text #1      | 
| img1 img2 Text #2     img3 | 
+-----------------------------------------+ 

Текст # 1 и текст # 2 должны быть приведены в соответствие, как я пытался показать. Я рассматриваю два различных подхода:

+-----------------------------------------+ 
|<- margin->Text #1      | 
+-----------------------------------------+ 
| img1 img2 Text #2     img3 | 
+-----------------------------------------+ 

Или

+----------+-------+----------------------+ 
|   |Text #1|      | 
|   +-------+ 
| img1 img2|Text #2|     img3 | 
+----------+-------+----------------------+ 

Я предпочитаю последний, но в LinearLayout с текстом # 1/# 2 рода обвалов, так что текст # 2 не видно.

Оба решения вложены внутри RelativeLayout. Я попытался установить гравитацию на LinearLayout, содержащую левую часть, на «левую», а с img3 на «правую», но, видимо, можно только придать гравитацию окружающему RelativeLayout право? По крайней мере, я не могу правильно выровнять гравитацию.

Если мои слабые рисунки имеют смысл, кто-нибудь может мне помочь в выборе правильного подхода?

ответ

2

Я хотел бы использовать относительную раскладку с этим изнутри:

linearLayout : parentBottom + vertical orientation 
    tv1 
    tv2 
img2: parentBottom + leftOf layout 
img1: parentBottom + leftOf img2 
img3 : parentBottom + rightOf layout 
1

Я использую weightSum и ориентацию для создания макета в соответствии с вашими потребностями

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

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/homeTableLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" 
     android:weightSum="10" 
     > 

     <LinearLayout 
      android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" 
     android:weightSum="10" 
     android:layout_weight="2" 
      > 
    <ImageView 
     android:layout_height="50dip" 
     android:layout_width="0dip" 
     android:background="@android:color/holo_blue_dark" 
     android:layout_weight="5" 
     /> 
    <ImageView 
     android:layout_height="50dip" 
     android:layout_width="0dip" 
     android:background="@android:color/holo_green_dark" 
     android:layout_weight="5" 
     /> 
    </LinearLayout> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/homeTableLayout" 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:layout_weight="3" 
     > 
     <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="25dip" 
       android:text="testing" 
       android:background="@android:color/holo_orange_dark" 
      /> 
     <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="25dip" 
       android:text="testing" 
       android:background="@android:color/holo_purple" 
      /> 

    </LinearLayout> 

    <LinearLayout 
      android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" 
     android:layout_weight="5" 
      > 
    <ImageView 
     android:layout_height="50dip" 
     android:layout_width="fill_parent" 
     android:background="@android:color/holo_blue_dark" 

     /> 

    </LinearLayout> 
    </LinearLayout> 

Внизу Каркасная. Измените его в соответствии с вашими потребностями:

enter image description here

+0

Спасибо! Попробуем, когда вернусь к моему коду :-) weightSum ... никогда не слышал об этом ... – CJe

+0

weightsum определяет, сколько областей будет занимать занимать по высоте или по ширине. – KDeogharkar

+1

http://stackoverflow.com/questions/7452741/what-is-androidweightsum-in-android-and-how-does-it-work – KDeogharkar

0

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/RelativeLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="68dp" 
    android:src="@drawable/ic_launcher" /> 

<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView1" 
    android:layout_marginLeft="19dp" 
    android:layout_toRightOf="@+id/imageView1" 
    android:src="@drawable/ic_launcher" /> 


<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/imageView2" 
    android:layout_alignTop="@+id/imageView2" 
    android:layout_marginLeft="34dp" 
    android:layout_toRightOf="@+id/imageView2" 
    android:text="Large Text" 
    android:gravity="center" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 


<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/textView1" 
    android:layout_alignRight="@+id/textView1" 
    android:layout_marginBottom="16dp" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<ImageView 
    android:id="@+id/imageView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@+id/textView1" 
    android:src="@drawable/ic_launcher" /> 

если не работает пожалуйста интимная

2

Далее можно разделить эти 3 линейных макетов одинаково используя WEIGHTSUM свойство

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

    <ImageView    
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitXY" 
     android:src="@drawable/img2"/> 

    <ImageView    
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitXY" 
     android:src="@drawable/img2"/> 
</LinearLayout> 



    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="80dip" 
     android:orientation="vertical" 
     android:weightSum="1"> 

     <TextView 
      android:id="@+id/direzione" 
      android:layout_width="wrap_content" 
      android:layout_height="0dip" 
      android:layout_weight="0.5"     
      android:text="Text View 1" 
      android:textColor="#000000"/> 

     <TextView 
      android:id="@+id/direzione_value" 
      android:layout_width="wrap_content" 
      android:layout_height="0dip" 
      android:layout_weight="0.5" 
      android:text="Text View 2" 
      android:textColor="#000000" /> 
    </LinearLayout> 

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

     <ImageView    
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitXY" 
     android:src="@drawable/img2"/> 
    </LinearLayout> 

enter image description here

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