繁体   English   中英

Android布局:如何实现这种特殊外观?

[英]Android layout: How to achieve this particular look?

我在使用Android布局时遇到困难,我感觉它一直在随机捕捉/调整大小/移动。 我正在尝试实现这种特殊的布局,但是我不知道如何。

我希望布局看起来如何

任何帮助/技巧,以实现这种布局将不胜感激!

这是我尝试过的代码:

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 };
}

在这里尝试一些重要的事情:layout_span。 有了它,您可以在html表中执行colspan之类的操作

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM