Android开发拖拉图片Gallery画廊组…

本文详细介绍了如何在Android应用中使用LinearLayout布局管理器来创建网格布局和图像切换器,同时通过实例展示了如何实现图像轮播和画廊功能。
Android开发拖拉图片Gallery画廊组件的使用--SimpleAdapter

新建grid_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <ImageView 
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="center"/>

</LinearLayout>

main.xml
<LinearLayout 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:orientation="vertical"
    tools:context=".MainActivity" 
    android:gravity="bottom">
    <ImageSwitcher 
        android:id="@+id/imageswitcher"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    
    <Gallery 
        android:id="@+id/myGallery"
        android:layout_gravity="center_vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:spacing="3px"/>
    

</LinearLayout>

main.java

package com.example.gallerydemo;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ViewSwitcher.ViewFactory;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class MainActivity extends Activity {

private Gallery myGallery=null;
private SimpleAdapter simpleAdapter=null;
private ImageSwitcher imageswitcher=null;
private List<Map<String,Integer>> list=new ArrayList<Map<String,Integer>>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.myGallery=(Gallery) super.findViewById(R.id.myGallery);
this.initAdapter();
this.myGallery.setAdapter(this.simpleAdapter);
this.myGallery.setOnItemClickListener(new OnItemClickListenerImp());
this.imageswitcher=(ImageSwitcher) super.findViewById(R.id.imageswitcher);
this.imageswitcher.setFactory(new ViewFactoryImp());
}
private void initAdapter(){
//取得全部的属性
Field[] fields=R.drawable.class.getDeclaredFields();
for(int i=0;i<fields.length;i++){
//System.out.println(fields[i]);
if(fields[i].getName().startsWith("ispic_")){
Map<String,Integer> map=new HashMap<String, Integer>();
try {
//必须指定名称是img
map.put("img", fields[i].getInt(R.drawable.class));
} catch (Exception e) {
// TODO: handle exception
}
this.list.add(map);
}
}
//如果使用SimpleAdapter需要自己定义内部的布局文件
this.simpleAdapter=new SimpleAdapter(this,this.list , 
R.layout.grid_layout, 
new String[]{"img"}, 
new int[]{R.id.img});
}
private class OnItemClickListenerImp implements OnItemClickListener{

public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Map<String,Integer> map=(Map<String, Integer>) parent.getAdapter().getItem(position);
MainActivity.this.imageswitcher.setImageResource(map.get("img"));
}
}
private class ViewFactoryImp implements ViewFactory{

public View makeView() {
ImageView img=new ImageView(MainActivity.this);
img.setBackgroundColor(0xFFFFFFFF);
img.setScaleType(ImageView.ScaleType.CENTER);
img.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
return img;
}
}

}
下载方式:https://renmaiwang.cn/s/t0445 在时序发生器设计实验中,如何达成T4至T1的生成? 时序发生器的构建可以通过运用一个4位循环移位寄存器来达成T4至T1的输出。 具体而言:- **CLR(清除)**: 作为全局清零信号,当CLR呈现低电平状态时,所有输出(涵盖T1至T4)皆会被清除。 - **STOP**: 在T4脉冲的下降沿时刻,若STOP信号处于低电平状态,则T1至T4会被重置。 - **启动流程**: 当启动信号START处于高电平,并且STOP为高电平时,移位寄存器将在每个时钟的上升沿向左移动一位。 移位寄存器的输出端对应了T4、T3、T2、T1。 #### 2. 时序发生器如何调控T1至T4的波形形态? 时序发生器通过以下几个信号调控T1至T4的波形形态:- **CLR**: 当CLR处于低电平状态时,所有输出均会被清零。 - **STOP**: 若STOP信号为低电平,且在T4脉冲的下降沿时刻,所有输出同样会被清零。 - **START**: 在START信号有效(通常为高电平),并且STOP为高电平时,移位寄存器启动,从而产生环形脉冲输出。 ### 微程序控制器实验#### 3. 微程序控制器实验中的四条机器指令及其对应的微程序段指定的机器指令及其关联的微程序段如下:- **NOP**: 00- **R0->B**: 04- **A+B->R0**: 05- **P<1>**: 30- **IN->R0**: 32- **R0->OUT**: 33- **HLT**: 35#### 4. 微程序段中的微操作/微命令序列针对每条微指令,其对应的微操作或微命令序列如下:- **IN->R0**: 输入(IN)单元的数据被...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值