Commit 47585350 by gao.chao

轮播,图片加载

parent 0fccab18
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".LoadingPicturesActivity" />
<activity android:name=".BannerActivity" />
<activity android:name=".ViewActviity" /> <activity android:name=".ViewActviity" />
<activity android:name=".QRActivity" /> <activity android:name=".QRActivity" />
<activity android:name=".TitleActivity" /> <activity android:name=".TitleActivity" />
......
package com.mayi.demo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.view.PicassoImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.transformer.FlipHorizontalTransformer;
import java.util.ArrayList;
import java.util.List;
public class BannerActivity extends BaseActivity implements OnBannerListener {
List list = new ArrayList();
List listText = new ArrayList();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_banner);
list.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic1xjab4j30ci08cjrv.jpg");
list.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic21363tj30ci08ct96.jpg");
list.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic259ohaj30ci08c74r.jpg");
list.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic2b16zuj30ci08cwf4.jpg");
list.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic2e7vsaj30ci08cglz.jpg");
listText.add("1");
listText.add("2");
listText.add("3");
listText.add("4");
listText.add("5");
Banner banner1 = findViewById(R.id.banner1);
banner1.setIndicatorGravity(BannerConfig.LEFT);//设置指示器位置
banner1.updateBannerStyle(BannerConfig.NUM_INDICATOR_TITLE);//设置样式
banner1.setImages(list)
.setBannerTitles(listText)//设置图片文字
.setBannerAnimation(FlipHorizontalTransformer.class)//设置动画
.setImageLoader(new PicassoImageLoader())
.setOnBannerListener(this)
.start();
Banner banner2 = findViewById(R.id.banner2);
List<Integer> list = new ArrayList<>();
list.add(R.mipmap.b1);
list.add(R.mipmap.b2);
list.add(R.mipmap.b3);
banner2.setImages(list)
.setImageLoader(new PicassoImageLoader())
.start();
}
@Override
public void OnBannerClick(int position) {
showToast("position=" + position);
}
}
package com.mayi.demo;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.view.LoadingPictures;
import java.io.File;
public class LoadingPicturesActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loading_pictures);
ImageView img1 = findViewById(R.id.img1);
LoadingPictures.loadUri("http://ww4.sinaimg.cn/large/006uZZy8jw1faic1xjab4j30ci08cjrv.jpg", img1);
ImageView img2 = findViewById(R.id.img2);
LoadingPictures.loadFile(new File(Environment.getExternalStorageDirectory() + "/2.jpg"), img2);
}
}
package com.mayi.demo;
import com.mayi.fastdevelop.base.BaseActivity;
public class SmartRefreshLayoutActivity extends BaseActivity{
}
...@@ -2,10 +2,12 @@ package com.mayi.demo; ...@@ -2,10 +2,12 @@ package com.mayi.demo;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View; import android.view.View;
import com.mayi.fastdevelop.base.BaseActivity; import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.util.DialogUtils; import com.mayi.fastdevelop.util.DialogUtils;
import com.mayi.fastdevelop.util.LogUtils;
import com.mayi.fastdevelop.util.ToastUtil; import com.mayi.fastdevelop.util.ToastUtil;
import com.mayi.fastdevelop.view.wheel.ChangeAddressDialog; import com.mayi.fastdevelop.view.wheel.ChangeAddressDialog;
import com.mayi.fastdevelop.view.wheel.ChangeBirthDialog; import com.mayi.fastdevelop.view.wheel.ChangeBirthDialog;
...@@ -131,5 +133,18 @@ public class ViewActviity extends BaseActivity { ...@@ -131,5 +133,18 @@ public class ViewActviity extends BaseActivity {
} }
}); });
findViewById(R.id.b10).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoActivity(BannerActivity.class);
}
});
findViewById(R.id.b11).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoActivity(LoadingPicturesActivity.class);
}
});
} }
} }
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加载网络图片及设置动画,设置样式,设置指针位置" />
<com.youth.banner.Banner
android:id="@+id/banner1"
android:layout_width="match_parent"
android:layout_height="@dimen/im_dp_150" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加载本地图片" />
<com.youth.banner.Banner
android:id="@+id/banner2"
android:layout_width="match_parent"
android:layout_height="@dimen/im_dp_150" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Github地址: https://github.com/youth5201314/banner" />
</LinearLayout>
</ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加载网络图片"/>
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加载本地图片"/>
<ImageView
android:id="@+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
\ No newline at end of file
...@@ -64,5 +64,18 @@ ...@@ -64,5 +64,18 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="标题栏" /> android:text="标题栏" />
<Button
android:id="@+id/b10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="图片轮播控件" />
<Button
android:id="@+id/b11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="图片加载" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
\ No newline at end of file
...@@ -26,10 +26,12 @@ android { ...@@ -26,10 +26,12 @@ android {
dependencies { dependencies {
api fileTree(include: ['*.jar'], dir: 'libs') api fileTree(include: ['*.jar'], dir: 'libs')
api 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.3'//下拉刷新,加载更多
api 'com.youth.banner:banner:1.4.10' //图片轮播控件
api "com.tencent.bugly:crashreport_upgrade:1.3.4" api "com.tencent.bugly:crashreport_upgrade:1.3.4"
api 'com.tencent.bugly:nativecrashreport:3.6.0.1' api 'com.tencent.bugly:nativecrashreport:3.6.0.1'
api 'com.squareup.okhttp3:okhttp:3.10.0' api 'com.squareup.okhttp3:okhttp:3.10.0'
api 'com.squareup.picasso:picasso:2.5.2' api 'com.squareup.picasso:picasso:2.5.2'//图片加载
api 'com.tencent.bugly:crashreport_upgrade:1.3.4' api 'com.tencent.bugly:crashreport_upgrade:1.3.4'
api 'com.tencent.bugly:nativecrashreport:3.6.0.1' api 'com.tencent.bugly:nativecrashreport:3.6.0.1'
api 'com.orhanobut:logger:2.2.0' api 'com.orhanobut:logger:2.2.0'
...@@ -40,5 +42,5 @@ dependencies { ...@@ -40,5 +42,5 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api files('libs/zixing-core-3.2.0.jar') api files('libs/zixing-core-3.2.0.jar')
implementation files('libs/tbs_sdk_thirdapp_v3.6.0.1371_43624_sharewithdownload_withoutGame_obfs_20181106_121046.jar') implementation files('libs/tbs_sdk_thirdapp_v3.6.0.1371_43624_sharewithdownload_withoutGame_obfs_20181106_121046.jar')//腾讯X5浏览器
} }
...@@ -6,6 +6,7 @@ import android.os.Bundle; ...@@ -6,6 +6,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import com.mayi.fastdevelop.util.ToastUtil;
import com.mayi.fastdevelop.view.LoadingDialog; import com.mayi.fastdevelop.view.LoadingDialog;
public abstract class BaseActivity extends AppCompatActivity { public abstract class BaseActivity extends AppCompatActivity {
...@@ -72,6 +73,10 @@ public abstract class BaseActivity extends AppCompatActivity { ...@@ -72,6 +73,10 @@ public abstract class BaseActivity extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} }
public void showToast(String msg){
ToastUtil.show(this,msg);
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
dismssLoadingDialog(); dismssLoadingDialog();
......
package com.mayi.fastdevelop.view;
import android.widget.ImageView;
import com.mayi.fastdevelop.R;
import com.squareup.picasso.Picasso;
import java.io.File;
/**
* 加载图片
*/
public class LoadingPictures {
public static int error = R.mipmap.loading_pictures_error_icon;
public static int placeholder = R.mipmap.loading_pictures_placeholder_icon;
public static void loadUri(String url, ImageView img) {
Picasso.with(img.getContext())
.load(url)
.resize(2000, 2000)
.onlyScaleDown() // 如果图片规格大于2000*2000,将只会被resize
.placeholder(placeholder)
.error(error)
.into(img);
}
public static void loadFile(File file, ImageView img) {
Picasso.with(img.getContext())
.load(file)
.placeholder(placeholder)
.error(error)
.into(img);
}
public static void loadFile(String pathname, ImageView img) {
loadFile(new File(pathname),img);
}
}
package com.mayi.fastdevelop.view;
import android.content.Context;
import android.net.Uri;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import com.youth.banner.loader.ImageLoader;
import java.io.File;
/**
* 支持加载本地图片,网络图片,文件中图片
*/
public class PicassoImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
if (path instanceof String) {
Picasso.with(context).load((String) path).into(imageView);
} else if (path instanceof Integer) {
Picasso.with(context).load((Integer) path).into(imageView);
} else if (path instanceof Uri) {
Picasso.with(context).load((Uri) path).into(imageView);
} else if (path instanceof File) {
Picasso.with(context).load((File) path).into(imageView);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment