当前位置:首页 » 安卓系统 » androidgallery显示

androidgallery显示

发布时间: 2024-07-09 17:35:24

㈠ android Gallery 放大至全屏怎么做

图片放大的思路:
第一、可以通过Matrix对象来变换图像,在选择的时候放大,在失去焦点的时候,缩小到原来的大小。

double scale = 1.2;
int width = bm.getWidth();
int height = bm.getHeight();
Log.i("size:", width+"");
float scaleWidth = (float)(scale*width);
float scaleHeight = (float)(scale*height);
Log.i("size:", scaleWidth+"");
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
bm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);

第二 、通过动画

<?xml version="1.0" encoding="utf-8"?>

<scale
xmlns:android="http://schemas.android.com/apk/res/android"

android:interpolator="@android:anim/decelerate_interpolator"

android:fromXScale="1"
android:toXScale="1.1"
android:fromYScale="1"
android:toYScale="1.1"

android:pivotX="50%"
android:pivotY="50%"
android:ration="500">

</scale>

第三、通过setLayoutParams

view.setLayoutParams(new Gallery.LayoutParams(150,150));
int mCounts = g.getCount() - 1;
if(position>0 && (position < mCounts)){
g.getChildAt(position - 1).setLayoutParams(new Gallery.LayoutParams(136, 88));
g.getChildAt(position + 1).setLayoutParams(new Gallery.LayoutParams(136, 88));
}
if(position == 0){
g.getChildAt(position + 1).setLayoutParams(new Gallery.LayoutParams(136, 88));
}
if(position == mCounts){
g.getChildAt(position - 1).setLayoutParams(new Gallery.LayoutParams(136, 88));
}

注释:其中(136, 88)是gallery中图片的大小,是在ImageAdapter里面设置的。(150,150)是选中图片放大后的大小,可以随便设置,只要跟(136, 88)区别就行了,是为了观察变化,我设置的是150而已。

第四 、通过动画和LayoutParam结合

gallery.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public
void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
ImageView v = (ImageView)arg1;
if(tempView != null && v.hashCode() != tempView.hashCode()){
tempView.setLayoutParams(new Gallery.LayoutParams(50,50));
}
v.startAnimation(toLarge);
tempView = v;
v.setLayoutParams(new Gallery.LayoutParams(60,60));
//
//v.setLayoutParams(new Gallery.LayoutParams(130,130));
tvName.setText(tempList.get(arg2).getPicName());
}
@Override
public
void onNothingSelected(AdapterView<?> arg0) {
tvName.setText("Nothing selected .");
}
});

㈡ 镐庢牱钖悭ndroid镄凣allery閲屽姩镐佹坊锷犲浘鐗囷纻

锲剧墖镓鎻忓嚭path锛屼娇鐢―rawable绫荤殑闱欐佹柟娉 createFromPath锛坧ath锛夊缑鍒颁竴涓狣rawable,鎶婅繖涓狣rawable锷犲叆涓涓鏁扮粍涓銆备娇鐢˙aseAdapter缁戝畾Galley锛宎dpter涓镄刧etcount锛堬级杩斿洖鏁扮粍闀垮害銆

㈢ android画廊怎样做出超炫效果

首先来看下面的效果:

从上面的图片可以看到,当添加多张图片的时候,能够在下方形成一个画廊的效果,我们左右拉动图片来看我们添加进去的图片,效果是不是好了很多呢?下面来看看怎么实现吧!


上面的效果类似Android里面ViewPage的效果,但是跟ViewPager有所不同,ViewPager每次只能显示一张图片。


其实我们是利用到了View的clipChildren属性,我们在这里要把ViewPager以及它的父窗体都设置为false,如下:


android:clipChildren="false"


因为如果clipChildren属性设置为true,就表明我们要将children给clip掉,就是说对于子元素来说,超出当前view的部分都会被切掉,那我们在这里把它设置成false,就表明超出view的部分,不要切掉,依然显示。


xml代码部分:


<!-- 配置container和pager的clipChildren=false, 并且指定marginLeft 和 marginRight 的值-->


<LinearLayout

android:id="@+id/container"

android:layout_width="match_parent"

android:layout_height="100dp"

android:clipChildren="false"

android:gravity="center_horizontal"

android:layerType="software"

android:orientation="horizontal" >

<android.support.v4.view.ViewPager

android:id="@+id/viewpager"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginLeft="110dp"

android:layout_marginRight="110dp"

android:clipChildren="false" >

</android.support.v4.view.ViewPager>

</LinearLayout>


Java代码部分:


// 1.设置幕后item的缓存数目

mViewPager.setOffscreenPageLimit(3);

// 2.设置页与页之间的间距

mViewPager.setPageMargin(10);

// 3.将父类的touch事件分发至viewPgaer,否则只能滑动中间的一个view对象

container.setOnTouchListener(new View.OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

return mViewPager.dispatchTouchEvent(event);

}

});

热点内容
thinkphp字段缓存 发布:2025-05-17 13:52:01 浏览:574
山灵app安卓版如何设置 发布:2025-05-17 13:51:49 浏览:387
帆布压缩袋 发布:2025-05-17 13:26:27 浏览:457
c语言16进制表示方法 发布:2025-05-17 13:11:25 浏览:480
ftp单位 发布:2025-05-17 13:10:03 浏览:142
c语言编写n的阶乘 发布:2025-05-17 13:10:02 浏览:685
lockjava 发布:2025-05-17 13:02:08 浏览:311
只狼和看门狗哪个配置高 发布:2025-05-17 12:50:21 浏览:206
扁桃玩的服务器地址 发布:2025-05-17 12:18:25 浏览:513
u盘上传歌 发布:2025-05-17 12:14:51 浏览:617