zoukankan      html  css  js  c++  java
  • Gallery过时替代方案HorizontalScrollView

    布局:

    <?xml version="1.0" encoding="utf-8"?>
    <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:background="#ff0000"
        tools:context="me.chunsheng.hongbao.activities.GallaryActivity">
    
        <ImageView
            android:id="@+id/displayImage"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.0" />
    
        <HorizontalScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:id="@+id/mygallery"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" />
        </HorizontalScrollView>
    
    
    </RelativeLayout>
    

      

    代码:

    package me.chunsheng.hongbao.activities;
    
    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    
    import java.io.IOException;
    import java.io.InputStream;
    
    import me.chunsheng.hongbao.R;
    
    public class GallaryActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_gallary);
    
            final ImageView diplayImage = (ImageView) findViewById(R.id.displayImage);
            final LinearLayout myGallery = (LinearLayout) findViewById(R.id.mygallery);
    
            try {
                String galleryDirectoryName = "gallery";
                String[] listImages = new String[3];
                for (int i = 0; i < 4; i++) {
                    //InputStream is = getAssets().open(galleryDirectoryName + "/" + imageName);
                    //final Bitmap bitmap = BitmapFactory.decodeStream(is);
    
                    ImageView imageView = new ImageView(getApplicationContext());
                    imageView.setLayoutParams(new ViewGroup.LayoutParams(700, 700));
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    imageView.setImageResource(R.mipmap.mayun);
                    imageView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            diplayImage.setImageResource(R.mipmap.bg_action_bar);
                        }
                    });
    
                    myGallery.addView(imageView);
                }
            } catch (Exception e) {
            }
        }
    }
    

      

  • 相关阅读:
    性能监控工具之----PerfMon Metrics Collector
    idea 常用设置记录
    springboot 初体验之踩坑篇
    Interleave controller-jmeter
    js怎么判断一个类型是否为数组类型
    加载完成事件
    Jquery-查找
    Dom-增加、删除
    Dom-修改
    Dom-查找
  • 原文地址:https://www.cnblogs.com/spring87/p/5234929.html
Copyright © 2011-2022 走看看