2016-03-31 16 views
0

私のアプリでURLから画像を読み込もうとすると、画像が1つだけ表示されますが、両方の画像が水平に表示されるようにするには...両方の画像が同時に表示されます。動的に画像ビューを投稿することができません

は、ここに私のmainactivityです:

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

    } 
} 
+0

ない水平に、あなたはあなたのTableLayoutに行を追加しているので、その表示は、垂直ではないでしょうか? –

+0

まあまあ垂直でも... btは1つの画像しか画面に表示されません... btw返信ありがとう:) –

+0

コードを実行しないと、何もしていないようです。 「1つの画像」と言うと、別のURLを使用していますか? –

答えて

1

あなたのレイアウトXMLを追加することはできますか?

私は

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="rocks.throw20.myapplication.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <TableLayout 
    android:id="@+id/table" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


</TableLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email" /> 

</android.support.design.widget.CoordinatorLayout> 

activity_main.xml MainActivityからあなたの正確な同じコードを使用すると、これは、それがどのように見えるかで、正常にこのレイアウトを使用してコードをテストすることができました。

Loading images into TableRows

+0

こんにちは私はそれを得た....多分それはちょうどエミュレータで問題だった...私はそれが2つの画像をロードしていた私の電話でそれを走った...非常に感謝u ..私はそれを..ありがとう:) –

関連する問題