【发布时间】:2016-07-20 03:56:09
【问题描述】:
每当我尝试从我的应用程序中的 url 加载图像时..只显示一个图像,但我希望两个图像都像列一样水平显示...请帮助我。我希望两个图像都是一个接一个地同时显示。
这是我的主要活动:
package com.example.hp.gotcha;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import com.squareup.picasso.Picasso;
public class MainActivity extends AppCompatActivity {
public String[] urls;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
urls = new String[]{"url1...","url2...",};
TableLayout table = (TableLayout) findViewById(R.id.table);
TableRow tr = new TableRow(this);
TableRow.LayoutParams lay = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
ImageView image = new ImageView(this);
Picasso.with(this).load(urls[0]).into(image);
tr.addView(image, lay);
table.addView(tr);
TableRow tr1 = new TableRow(this);
TableRow.LayoutParams lay1 = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
ImageView image1 = new ImageView(this);
Picasso.with(this).load(urls[1]).into(image1);
tr.addView(image1, lay1);
table.addView(tr1);
}
}
【问题讨论】:
-
您正在向 TableLayout 中添加行,所以不是垂直显示,而不是水平显示吗?
-
好吧,即使是垂直的也可以……但是屏幕上只有一张图像是问题所在……顺便说一句,谢谢您的回复:)
-
不运行代码,我看不出你在做什么有什么问题。当您说“一张图片”时,您确定您使用的是不同的网址吗?
-
是的,当然....实际上第一张图片与下一张重叠...当我尝试使用 for 循环做同样的事情时...nd 使用 urls[i ] 而不是 0 或 1 ...我的应用程序崩溃了..
-
您能否在您的
activity_main.xml文件中添加edit,好吗?
标签: android android-layout picasso