小编Toy*_*oye的帖子

如何在代码中使用picasso设置背景图像

我知道毕加索将图像加载到imageview等,但如何使用毕加索设置我的布局背景图像?

我的代码:

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativelayout);
        relativeLayout.setBackgroundResource(R.drawable.table_background);
        Picasso.with(MainActivity.this)
                .load(R.drawable.table_background)
                .resize(200, 200)
                .into(relativeLayout);
        return relativeLayout;
    }
Run Code Online (Sandbox Code Playgroud)

我在这里给出了任何错误,说它无法解决.我有一个ScrollView和相对布局.

java android android-scrollview picasso android-relativelayout

25
推荐指数
1
解决办法
2万
查看次数

getReseources()位图数组的NullPointerException

我是Android开发的新手,遇到了一个问题,我正在尝试创建一个在图库中显示的图像数组,当我点击图片时,它会显示底部的图片.当我运行应用程序时,它崩溃了.我能得到的任何帮助都会非常有帮助.并提前感谢.

我的问题是

  1. 我怎么摆脱NullPointerException
  2. 我正确解码图片?有人能告诉我一个更好的方法吗?

谢谢

我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".PicturesActivity" >

    <Gallery
        android:id="@+id/gallery1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="16dp" />

    <ImageView
        android:id="@+id/image1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/trophykiss" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我的课:

public class PicturesActivity extends Activity {   

    Bitmap[] myImages = new Bitmap[] {
         BitmapFactory.decodeResource(getResources(), R.drawable.champions),
         BitmapFactory.decodeResource(getResources(), R.drawable.trophykiss),
         BitmapFactory.decodeResource(getResources(), R.drawable.championstwo),
         BitmapFactory.decodeResource(getResources(), R.drawable.trophies),
         BitmapFactory.decodeResource(getResources(), R.drawable.culture),
         BitmapFactory.decodeResource(getResources(), R.drawable.maintrophy),
         BitmapFactory.decodeResource(getResources(), R.drawable.dive),
         BitmapFactory.decodeResource(getResources(), R.drawable.naijamain),
         BitmapFactory.decodeResource(getResources(), R.drawable.ethiopia),
         BitmapFactory.decodeResource(getResources(), R.drawable.peru),
         BitmapFactory.decodeResource(getResources(), R.drawable.funtime),
         BitmapFactory.decodeResource(getResources(), R.drawable.skils),
         BitmapFactory.decodeResource(getResources(), R.drawable.gabon),
         BitmapFactory.decodeResource(getResources(), R.drawable.gambia),
         BitmapFactory.decodeResource(getResources(), R.drawable.guinea)
    };


    private ImageView imageView; …
Run Code Online (Sandbox Code Playgroud)

java android bitmap nullpointerexception android-layout

8
推荐指数
1
解决办法
450
查看次数