动态布局imageViews

问题描述:

请帮助我建立布局这样的画面: 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

入住此示例布局,您可以自定义该为自己的

<?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