我对这段代码有些问题.我正在尝试使用以下格式创建动态新闻列表:
|image| - title
|image|- subtitle
Run Code Online (Sandbox Code Playgroud)
这是我的小cicle代码(随机数据的一个例子)
void setListNews(List<Map<String,String>>l){
listaNewsPagina = l;
final Iterator ite = listaNewsPagina.iterator();
LinearLayout lin = (LinearLayout)findViewById(R.id.linear_sezione_news);
LinearLayout lineare = (LinearLayout)findViewById(R.id.lineare);
while(ite.hasNext()){
Map<String,String> map = (Map<String, String>) ite.next();
ImageView imm = (ImageView)findViewById(R.id.immagine);
RelativeLayout rl = (RelativeLayout)findViewById(R.id.relative);
TextView titolo = (TextView)findViewById(R.id.titolo);
TextView sottoTitolo = (TextView)findViewById(R.id.sottoTitolo);
titolo.setText("titolooooo");
sottoTitolo.setText("sottoTitoloooooooooooo");
rl.addView(titolo);
rl.addView(sottoTitolo);
lineare.addView(imm);
lineare.addView(rl);
}
lin.addView(lineare);
setContentView(lin);
Run Code Online (Sandbox Code Playgroud)
这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linear_sezione_news"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_homepage" >
<LinearLayout
android:id="@+id/lineare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#aadd99"
>
<ImageView
android:id="@+id/immagine"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="10dp"
android:layout_marginTop="4dp" …Run Code Online (Sandbox Code Playgroud) 我正在创建一个从网址下载图像的应用程序,将它们保存在设备上,之后必须将它们加载到具有固定大小的ImageView中.对于下载和保存文件我没有问题但是当我尝试在ImageView中设置图像时我有一个致命的错误,因为我的ImageView图像很大(我认为......).
这是xml文件:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff9f9f"
android:layout_margin="2dip"
android:padding="2dip">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff9f9f"
android:layout_margin="2dip"
android:padding="2dip">
<TextView
android:id="@+id/notizieTitolo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/immagineNotizie"
android:text="Titolo"
android:textColor="#6b71f1"
android:textSize="20dip"
android:layout_margin="2dip" />
<TextView
android:id="@+id/notizieSottoTitolo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/immagineNotizie"
android:text="SottoTitolo"
android:textSize="15dip"
android:layout_margin="2dip"/>
<ImageView
android:background="@drawable/icona"
android:id="@+id/immagineNotizie"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_margin="2dip" />
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
是一个带有ImageView的简单布局,一个位于ImageView右侧的TextView和一个TextView
重要的是ImageView with和height.设置为100dip(如果我计算2dip为保证金).
这个类的代码,图像保存在Bitmap中.
public class Notizia {
String url;
String titolo;
String sottoTitolo;
String nomeImmaginSalvata;
Bitmap immagine;
public Notizia(String tit, String sottoTit, Bitmap imm, String lk){
titolo = tit;
sottoTitolo = sottoTit;
immagine = …Run Code Online (Sandbox Code Playgroud)