如何在Android中构建此布局?

如何在Android中构建此布局?,android,Android,我找到了Fedor的代码并在我的项目中实现了它。唯一的区别是我的应用程序没有列表视图 我希望显示器看起来像下图: 我该怎么做 ImageAdapter.class public class ImageAdapter extends BaseAdapter { private Activity activity; // private Context context; private ArrayList<HashMap<String, String>> data; //

我找到了Fedor的代码并在我的项目中实现了它。唯一的区别是我的应用程序没有列表视图

我希望显示器看起来像下图:

我该怎么做

ImageAdapter.class

public class ImageAdapter extends BaseAdapter {
private Activity activity;
// private Context context;
private ArrayList<HashMap<String, String>> data;
// private int mThumbIds = (R.drawable.stub);
private static LayoutInflater inflat = null;
public Image image;

public ImageAdapter(Activity ac, ArrayList<HashMap<String, String>> d) {
    this.activity = ac;
    this.data = d;
    inflat = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    image = new Image(activity);
}

public int getCount() {
    // TODO Auto-generated method stub
    return data.size();
}

public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return arg0;
}

public long getItemId(int arg0) {
    // TODO Auto-generated method stub
    return arg0;
}

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View view = convertView;
    if (convertView == null) {
        view = inflat.inflate(R.layout.items, null);
    }

    ImageView images = (ImageView) view.findViewById(R.id.item);
    HashMap<String, String> imageMap = new HashMap<String, String>();
    imageMap = data.get(position);
    images.setImageResource(R.id.item);

    image.DisplayImage(imageMap.get("SOURCE"), images);
    return view;
}
公共类ImageAdapter扩展了BaseAdapter{
私人活动;
//私人语境;
私有数组列表数据;
//private int mThumbIds=(R.drawable.stub);
私用静态充气机充气=空;
公众形象;
公共图像适配器(活动ac,ArrayList d){
本活动=ac;
这个数据=d;
充气=(充气)活动
.getSystemService(上下文布局\充气机\服务);
图像=新图像(活动);
}
public int getCount(){
//TODO自动生成的方法存根
返回data.size();
}
公共对象getItem(int arg0){
//TODO自动生成的方法存根
返回arg0;
}
公共长getItemId(int arg0){
//TODO自动生成的方法存根
返回arg0;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
//TODO自动生成的方法存根
视图=转换视图;
if(convertView==null){
视图=充气。充气(R.layout.items,空);
}
ImageView images=(ImageView)view.findViewById(R.id.item);
HashMap imageMap=新的HashMap();
imageMap=data.get(位置);
image.setImageResource(R.id.item);
image.DisplayImage(imageMap.get(“源”),图像);
返回视图;
}
moinhact.class

public class MoiNhatAct extends Activity {

private static String url1 = "http://beta.photo.tamtay.vn/service/detail/getPhotoNews/4";

GridView g;
ImageAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stubs
    super.onCreate(savedInstanceState);
    setContentView(R.layout.aaa);

    ArrayList<HashMap<String, String>> imageList = new ArrayList<HashMap<String, String>>();

    // Creating JSON Parser instance
    JSONParser jParser = new JSONParser();

    // getting JSON string from URL
    JSONObject json = jParser.getJSONFromUrl(url1);

    JSONObject result;
    try {
        result = json.getJSONObject("result");
        String data_time = result.getString("Date time");
        String count = result.getString("Count");
        String page = result.getString("page");

        JSONArray ketqua = result.getJSONArray("ketqua");
        for (int i = 0; i < ketqua.length(); i++) {
            JSONObject j = ketqua.getJSONObject(i);
            String id = j.getString("id");
            String name = j.getString("name");
            String thumb = j.getString("thumb");
            String source = j.getString("source");
            JSONArray sizeArray = j.getJSONArray("size");
            String size = sizeArray.getString(0);

            HashMap<String, String> map = new HashMap<String, String>();
            map.put("DATE_TIME", data_time);
            map.put("COUNT", count);
            map.put("PAGE", page);
            map.put("ID", id);
            map.put("NAME", name);
            map.put("SOURCE", source);
            map.put("SIZE", size);

            imageList.add(map);

        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    g = (GridView) findViewById(R.id.gridAvarta);
    adapter = new ImageAdapter(this, imageList);
    g.setAdapter(adapter);

    g.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            Intent i = new Intent(getApplicationContext(),
                    ImageFullAct.class);
            // passing array index
            i.putExtra("id", position);
            startActivity(i);
        }
    });

    Button clear = (Button) findViewById(R.id.clearCache);
    clear.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            adapter.image.clearCache();
            adapter.notifyDataSetChanged();
        }
    });
}

public void onDestroy() {
    g.setAdapter(null);
    super.onDestroy();
}
公共类Moinhact扩展活动{
专用静态字符串url1=”http://beta.photo.tamtay.vn/service/detail/getPhotoNews/4";
网格视图g;
图像适配器;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.aaa);
ArrayList imageList=新建ArrayList();
//创建JSON解析器实例
JSONParser jParser=新的JSONParser();
//从URL获取JSON字符串
JSONObject json=jParser.getJSONFromUrl(url1);
JSONObject结果;
试一试{
result=json.getJSONObject(“结果”);
String data_time=result.getString(“日期时间”);
字符串计数=result.getString(“计数”);
String page=result.getString(“page”);
JSONArray ketqua=result.getJSONArray(“ketqua”);
对于(int i=0;i
}

这段代码我可以用Gridview显示图像。

但我可以自定义它看起来像下面的布局

现在我需要一个自定义布局和显示


<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:weightSum="5" >
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="2"/>

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="2" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:weightSum="4" >
        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/imageView5"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/imageView6"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <ImageView
            android:id="@+id/imageView7"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:weightSum="5" >

        <ImageView
            android:id="@+id/imageView8"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="2" />

        <ImageView
            android:id="@+id/imageView9"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

        <ImageView
            android:id="@+id/imageView10"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="2" />
    </LinearLayout>
</LinearLayout>

     for(int i = 0 ; i < 10 ; i++){
            try {
                int id = (Integer) R.id.class.getField("imageView"+(i+1)).get(null);
                ImageView imageView = (ImageView) findViewById(id);
                imageView.setImageBitmap(imageAdaper.getImage(i));
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
     }
对于(int i=0;i<10;i++){ 试一试{ intid=(整数)R.id.class.getField(“imageView”+(i+1)).get(null); ImageView ImageView=(ImageView)findViewById(id); setImageBitmap(imageAdaper.getImage(i)); }捕获(IllegalArgumentException e){ //TODO自动生成的捕捉块 e、 printStackTrace(); }捕获(安全异常e){ //TODO自动生成的捕捉块 e、 printStackTrace(); }捕获(非法访问例外e){ //TODO自动生成的捕捉块 e、 printStackTrace(); }捕获(无此字段例外){ //TODO自动生成的捕捉块 e、 printStackTrace(); } }
所有这些部分应该是什么?文本视图?图像视图?需要更多信息。我需要在Imageview中显示。每个单元格中有一个图像。嘿,伙计。你能帮我发送你的Skype或Yahoo吗……我有个问题……请帮我添加代码,以便使用Imageview.setImageUR动态查找图像视图并设置imagestry我(uri)或者请上传一些代码片段来展示你是如何加载图片的。你能和我聊天吗…帮帮我吗?