2016-07-08 9 views
0

5つのtextviewsをimageviewに整列しようとしています。私は2列5行のグリッドレイアウトを作成しました。列0には、5行で5つのテキストビューが分割されています。列1には、5行にわたる画像ビューがあります。しかし、私は私の希望のレイアウトを得ることができません。目的のレイアウト以下を参照してください。gridviewoutのtextviewとimageviewの整列

enter image description here

マイコード:

<GridLayout 
     android:id="@+id/gridlayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:columnCount="2" 
     android:layout_below="@+id/titel_over_ons"> 

     <TextView 
      android:id="@+id/intro" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="start" 
      android:layout_row="0" 
      android:layout_column="0" 
      android:text="" /> 

     <ImageView 
      android:id="@+id/foto_over_ons" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_column="1" 
      android:layout_row="0" 
      android:layout_gravity="end" 
      android:contentDescription="@string/dm_design_webdesign_moobiele_applicaties_en_grafische_vormgeving" /> 

     <TextView 
      android:id="@+id/titel_dr" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="15dp" 
      android:layout_row="1" 
      android:layout_column="0" 
      android:layout_gravity="start" 
      android:text="" /> 

     <TextView 
      android:id="@+id/tekst_dr" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="start" 
      android:layout_row="2" 
      android:layout_column="0" 
      android:layout_marginTop="10dp" /> 


     <TextView 
      android:id="@+id/titel_service" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="start" 
      android:layout_row="3" 
      android:layout_column="0" 
      android:layout_marginTop="15dp" 
      android:text="" /> 

     <TextView 
      android:id="@+id/tekst_service" 
      android:layout_width="0dp" 
      android:layout_gravity="start" 
      android:layout_height="wrap_content" 
      android:layout_row="4" 
      android:layout_column="0" 
      android:layout_marginTop="10dp" /> 


    </GridLayout> 

誰かがこの問題で私を助けることができますか? ありがとうございます。

+1

あなたが他のビューに以下具体的に次のビューを配置することができる相対的なレイアウトとのより良い運を持っていることがあります。 https://developer.android.com/reference/android/widget/RelativeLayout.html – BR89

+0

グリッドレイアウトを使用しないでください。空白と重量は考慮しません。必要な場合は、サポートv7のものを使用してください。これを簡単に達成するために、適切なスパンでTableLayoutを使用してください。 – Kushan

+0

私はTablelayoutを使用しようとしましたが、rowspanをサポートしていません –

答えて

1

このコードは、均等に分割TextViewsが表示されます:

(彼らはビューが提案しているだけのためのもので、背景を削除)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     > 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:layout_margin="5dp" 
      android:background="#222" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:layout_margin="5dp" 
      android:background="#675" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:layout_margin="5dp" 
      android:background="#989" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:layout_margin="5dp" 
      android:background="#e34" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:layout_margin="5dp" 
      android:background="#e76" /> 




    </LinearLayout> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="match_parent" 
     android:layout_marginStart="10dp" 
     android:background="#eae" 
     /> 



</LinearLayout>] 

Imagem de como ficaria

0

あなたはこれのいずれかを使用して要素のスパンを設定することができます属性:

あなたのケースでは
android:layout_columnSpan="..." 
android:layout_rowSpan="..." 

それは、このタイプのを設計するのが良いのxmlのためのコードの下

android:layout_columnSpan="5" 
+0

私は試みたが、それは助けにはならない。 –

0

使用されますレイアウト:

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="One" 
     android:background="@android:color/white"    
     android:layout_weight="1" 
     android:gravity="center"/> 

    <View 
     android:layout_height="5dp" 
     android:layout_width="match_parent"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="Two" 
     android:background="@android:color/white" 
     android:layout_weight="1" 
     android:gravity="center"/> 

    <View 
     android:layout_height="5dp" 
     android:layout_width="match_parent"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="Three" 
     android:background="@android:color/white" 
     android:layout_weight="1" 
     android:gravity="center"/> 

    <View 
     android:layout_height="5dp" 
     android:layout_width="match_parent"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="Four" 
     android:background="@android:color/white" 
     android:layout_weight="1" 
     android:gravity="center"/> 

    <View 
     android:layout_height="5dp" 
     android:layout_width="match_parent"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="Five" 
     android:background="@android:color/white" 
     android:layout_weight="1" 
     android:gravity="center"/>   

</LinearLayout> 

<View 
    android:layout_width="5dp" 
    android:layout_height="match_parent"/> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:background="@drawable/ic_launcher"/> 

</LinearLayout>