首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法动态发布图像视图

无法动态发布图像视图
EN

Stack Overflow用户
提问于 2016-03-31 23:33:35
回答 1查看 86关注 0票数 0

每当我尝试从app..only中的url加载图像时,都会显示一个图像,但我希望像columns...please中那样水平显示这两个图像。我希望两个图像一个接一个地同时显示。

以下是我的主要活动:

代码语言:javascript
复制
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);    

    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-04-01 00:20:37

你能添加你的布局xml吗?

我使用这个布局activity_main.xml成功地测试了您的代码

代码语言:javascript
复制
<?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>

使用与MainActivity中完全相同的代码,如下所示。

Loading images into TableRows

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36337757

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档