Gallery过时替代方案HorizontalScrollView

简介: 布局:      代码:   package me.chunsheng.hongbao.

布局:

<?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) {
        }
    }
}

  

目录
相关文章
|
4月前
|
Android开发
Android 开发 tablayout 字体加粗 ,简便的手法:
Android 开发 tablayout 字体加粗 ,简便的手法:
60 0
|
Android开发
Android RecyclerView实现吸顶动态效果,详细分析
Android RecyclerView实现吸顶动态效果,详细分析
高级UI系列(四) 扩展TextView 边角Drawable实战篇
高级UI系列(四) 扩展TextView 边角Drawable实战篇
90 0
高级UI系列(四) 扩展TextView 边角Drawable实战篇
|
Android开发
【Android的 Fragment 讲解与简单历史页面切换效果实践】
目录 第一节 概述 第二节 样例效果 第三节 生命周期 第四节 实践效果 第一节 概述 首先,提个问题,啥是 Fragment ? Fragment 是一种可以嵌入在 Activity 当中的 UI 片段,它能让程序更加合理和充分地利用大屏幕空间,因在平板上应用的非常广泛。 到这里你可能会有些懵,啥玩意?下面的举个例子:想象我们正在开发一个做一个页面,其中使用 RecyclerView 展示了一组新闻的标题,当点击了其中一个标题时,就打开另一个界面显示新闻的详细内容。如果...
140 0
【Android的 Fragment 讲解与简单历史页面切换效果实践】
|
XML API Android开发
Android笔记:底部导航栏的动态替换方案
Android笔记:底部导航栏的动态替换方案
132 0
|
Java Android开发 UED
android中ListView异步加载图片时的图片错位问题解决方案
android中ListView异步加载图片时的图片错位问题解决方案
|
XML API Android开发
Android动态换肤原理解析及实践
前言: 本文主要讲述如何在项目中,在不重启应用的情况下,实现动态换肤的效果。换肤这块做的比较好的,有网易云音乐,qq等,给用户带来了多样的界面选择和个性化定制。
2127 1
|
XML Java Android开发
Android换肤方案分析
## 0x0 背景 无论是出于用户个性化的考虑,或者是不同场景下的氛围渲染,客户端应用存在着换肤的需求。本文举出三种常见的换肤方案,并加以对比,以作后续参考。无论何种方案,换肤的核心都包含皮肤的管理,皮肤的加载,以及皮肤的生效。不同的方案在解决这些问题上有不同的思路。 ## 0x1 手动重新设置UI资源 这种方式最简单,在业务代码里面手动写设置新皮肤的逻辑,当新皮肤下发时,回调该逻辑重新
1951 0
|
Android开发 数据格式 XML
Android谷歌官方的自适应TextView字体大小的解决方案
Android谷歌官方的自适应TextView字体大小的解决方案 有时候UI限定了TextView宽度或者布局的控件空间尺寸不足,而此时的TextView里面的文本就无法完全正常显示。
3102 0