2014-11-01 60 views
0

我在Android的佈局方面遇到困難,我覺得它會隨機捕捉/調整大小/移動。我試圖達到這個特定的佈局,但我不知道如何。Android佈局:如何實現這個特定的外觀?

How I'd like the layout to look

實現這一佈局任何幫助/提示將不勝感激!

這是我曾嘗試代碼:

public class ImageAdapter extends BaseAdapter { 
    private Context mContext; 

    // Constructor 
    public ImageAdapter(Context c) { 
     mContext = c; 
    } 

    public int getCount() { 
     return mThumbIds.length; 
    } 

    public Object getItem(int position) { 
     return null; 
    } 

    public long getItemId(int position) { 
     System.out.println(position); 
     return 0; 
    } 

    // create a new ImageView for each item referenced by the Adapter 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ImageView imageView; 

     int imgSize = 0; 

     if (convertView == null) { 

      WindowManager wm = (WindowManager) mContext 
        .getSystemService(Context.WINDOW_SERVICE); 
      Display display = wm.getDefaultDisplay(); 
      Point size = new Point(); 
      display.getSize(size); 
      imgSize = size.x/4; 

      imageView = new ImageView(mContext); 
      imageView.setLayoutParams(new GridView.LayoutParams(imgSize, 
        imgSize)); 
      imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 

     } else { 
      imageView = (ImageView) convertView; 
     } 

     imageView.setImageResource(mThumbIds[position]); 

     imageView.setLayoutParams(new GridView.LayoutParams(imgSize * 2, 
       imgSize * 2)); 
     imageView.setImageResource(mThumbIds2[0]); 

     return imageView; 
    } 

    // Keep all Images in array 
    public Integer[] mThumbIds = { R.drawable.yourpic, R.drawable.yourpic, 
      R.drawable.yourpic, R.drawable.yourpic, R.drawable.yourpic, 
      R.drawable.yourpic, R.drawable.yourpic, R.drawable.yourpic, 
      R.drawable.yourpic, R.drawable.yourpic, R.drawable.yourpic, 
      R.drawable.yourpic, R.drawable.yourpic, R.drawable.yourpic, 
      R.drawable.yourpic, R.drawable.yourpic, R.drawable.yourpic, 
      R.drawable.yourpic, R.drawable.yourpic, R.drawable.yourpic, 
      R.drawable.yourpic, R.drawable.yourpic }; 

    public Integer[] mThumbIds2 = { R.drawable.bigpicture }; 
} 
+1

它看起來像一個網格佈局,或者我加入,我試圖OP代碼中的TableLayout – 2014-11-01 14:33:19

+0

。 – StackPWRequirmentsAreCrazy 2014-11-02 05:35:21

回答

1

嘗試這樣的事情 重要的位置:layout_span。與您可以這樣做合併單元格中的HTML表格

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

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_span="2" 
     android:src="@drawable/yourbigpic" /> 

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

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

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

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

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

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

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

<TableRow> 

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

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

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

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