2014-10-02 120 views
0

請幫助我建立佈局這樣的畫面: enter image description here動態佈局imageViews

圖片位置需要像在屏幕上。所有時間圖像縮放或調整邊界的大小。

<?xml version="1.0" encoding="utf-8"?> 

<TableLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:weightSum="3"> 

     <view 
      class=".widget.AvatarView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/view6" 
      android:gravity="center" 
      android:layout_weight="1" 
      android:layout_gravity="center" /> 

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="2"> 

      <view 
       class=".widget.AvatarView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/view" 
       android:gravity="center" /> 

      <view 
       class=".widget.AvatarView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/view11" 
       android:gravity="center" /> 
     </LinearLayout> 
    </TableRow> 

    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center"> 

     <view 
      class=".widget.AvatarView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/view5" 
      android:layout_weight="1" 
      android:gravity="center" /> 

     <view 
      class=".widget.AvatarView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/view8" 
      android:layout_weight="1" 
      android:gravity="center"> 

     </view> 

     <view 
      class=".widget.AvatarView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/view10" 
      android:layout_weight="1" 
      android:gravity="center"> 

     </view> 

    </TableRow> 
</TableLayout> 

但圖像不需要縮放和調整大小! 我收到enter image description here請幫忙,謝謝!

+0

嘗試['GridLayout'(http://developer.android.com/reference/android/widget/GridLayout.html)可能? – 2014-10-02 07:45:09

+0

而不是'TableLayout'使用帶有填充,方向和重量屬性的'LinearLayout'。 – 2014-10-02 07:47:03

+0

@HimanshuAgarwal我不能做線性佈局的彈性 – smail2133 2014-10-02 07:59:52

回答

0

入住此示例佈局,您可以自定義該爲自己的

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

    <ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" > 

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

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

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:src="@drawable/ic_launcher" /> 

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

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_launcher" /> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_launcher" /> 
      </LinearLayout> 
     </LinearLayout> 

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

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" 
       android:layout_weight="1"/> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" 
       android:layout_weight="1" /> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" 
       android:layout_weight="1"/> 
     </LinearLayout> 
    </LinearLayout> 
    </ScrollView> 
</RelativeLayout> 
+0

我需要在屏幕頂部的行爲,像tinder應用程序。 – smail2133 2014-10-02 09:36:04

+0

是從這段代碼你可以編輯根據你的需要它給出類似於上述佈局圖像 – 2014-10-02 09:37:47

+0

我的邏輯,一些計數圖像可以是空的,其他圖像是有彈性的,我不想要它!如何做到這一點? – smail2133 2014-10-02 09:41:23