第三方登入加RecyclerView加動畫
阿新 • • 發佈:2018-11-21
包名一定改成com.umeng.soexample
首先在清單檔案註冊
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<activity android:name=".wxapi.WXEntryActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:exported="true" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <activity android:name="com.tencent.tauth.AuthActivity" android:launchMode="singleTask" android:noHistory="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="tencent100424468" /> </intent-filter> </activity> <activity android:name="com.tencent.connect.common.AssistActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <activity android:name=".TwoActivity" /> <activity android:name=".ThreeActivity"></activity>
然後在APP下的build檔案
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
依賴
implementation files('libs/SecurityEnvSDK-release-1.1.0.jar') implementation files('libs/umeng-common-1.5.4.jar') implementation files('libs/umeng-share-core-6.9.3.jar') implementation files('libs/umeng-share-QQ-simplify-6.9.3.jar') implementation files('libs/umeng-share-wechat-simplify-6.9.3.jar') implementation files('libs/umeng-shareboard-widget-6.9.3.jar') implementation files('libs/umeng-sharetool-6.9.3.jar') implementation files('libs/utdid4all-1.1.5.3_proguard.jar') implementation 'com.squareup.picasso:picasso:2.3.2' implementation 'com.google.code.gson:gson:2.2.4' implementation 'com.squareup.okhttp3:okhttp:3.11.0' implementation 'com.android.support:recyclerview-v7:27.1.1'
佈局main
<?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"
tools:context=".MainActivity">
<ImageView
android:layout_centerInParent="true"
android:layout_marginTop="15dp"
android:src="@mipmap/ic_launcher"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/image1"
android:layout_below="@+id/view"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:textSize="20dp"
android:padding="15dp"
android:text="登入"
android:gravity="center_horizontal"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/text1"
android:id="@+id/view"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit1"
android:layout_below="@id/image1"
android:gravity="center_horizontal"
android:hint="賬號"
android:background="@drawable/fen"/>
<EditText
android:id="@+id/edit2"
android:layout_marginTop="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/edit1"
android:gravity="center_horizontal"
android:hint="密碼"
android:background="@drawable/fen"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn1"
android:text="登入"
android:layout_below="@id/edit2"
android:layout_margin="15dp"
android:background="@drawable/yuan"/>
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="微信"
android:onClick="weixinLogin"
android:layout_margin="15dp"
android:background="@drawable/yuan"
android:layout_centerInParent="true"
android:layout_below="@id/btn1"/>
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="QQ"
android:onClick="qqLogin"
android:layout_margin="15dp"
android:background="@drawable/yuan"
android:layout_centerInParent="true"
android:layout_below="@id/btn2"/>
</RelativeLayout>
MainActivity類
public class MainActivity extends AppCompatActivity implements LoginView{
public String TAG=this.getClass().getSimpleName();
public EditText edit1;
public EditText edit2;
public ImageView image;
public Button btn1, btn2, btn3;
public LoginPresenter mloginPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = findViewById(R.id.btn1);
btn2 = findViewById(R.id.btn2);
btn3 = findViewById(R.id.btn3);
edit1 = findViewById(R.id.edit1);
edit2 = findViewById(R.id.edit2);
image = findViewById(R.id.image1);
mloginPresenter = new LoginPresenter(this);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = edit1.getText().toString().trim();
String sex = edit2.getText().toString().trim();
if(name.equals("111")&&sex.equals("111")){
mloginPresenter.login(name,sex);
Intent intent = new Intent(MainActivity.this, TwoActivity.class);
startActivity(intent);
}else{
Toast.makeText(MainActivity.this, "失敗", Toast.LENGTH_LONG).show();
return;
}
}
});
}
//微信授權
public void weixinLogin(View view) {
authorization(SHARE_MEDIA.WEIXIN);
}
//qq每次登入授權
public void qqLogin(View view) {
UMShareConfig config = new UMShareConfig();
config.isNeedAuthOnGetUserInfo(true);
UMShareAPI.get(MainActivity.this).setShareConfig(config);
authorization(SHARE_MEDIA.QQ);
}
//授權
private void authorization(SHARE_MEDIA share_media) {
UMShareAPI.get(this).getPlatformInfo(this, share_media, new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
}
@Override
public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
Log.d(TAG, "onComplete " + "授權完成");
String uid = map.get("uid");
String openid = map.get("openid");
String unionid = map.get("unionid");
String access_token = map.get("access_token");
String refresh_token = map.get("refresh_token");
String expires_in = map.get("expires_in");
//稱呼
String name = map.get("name");
//性別
String gender = map.get("gender");
//頭像
String iconurl = map.get("iconurl");
Toast.makeText(getApplicationContext(), "openid=" + openid + ",name=" + name+"///"+iconurl, Toast.LENGTH_SHORT).show();
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String,String> next = iterator.next();
if(next.getKey().equals("iconurl")){
Picasso.with(MainActivity.this).load(next.getValue()).into(image);
Intent intent = new Intent(MainActivity.this, TwoActivity.class);
intent.putExtra("iconurl",iconurl);
intent.putExtra("name",name);
startActivity(intent);
}
if(next.getKey().equals("name")){
edit1.setText(next.getValue());
}
if(next.getKey().equals("openid")){
edit2.setText(next.getValue());
}
}
}
@Override
public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
Log.d(TAG, "onError " + "授權失敗");
}
@Override
public void onCancel(SHARE_MEDIA share_media, int i) {
Log.d(TAG, "onCancel " + "授權取消");
}
});
}
//分享
private UMShareListener shareListener = new UMShareListener() {
@Override
public void onStart(SHARE_MEDIA platform) {
}
@Override
public void onResult(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this, "成功了", Toast.LENGTH_LONG).show();
}
@Override
public void onError(SHARE_MEDIA platform, Throwable throwable) {
Toast.makeText(MainActivity.this, "失敗", Toast.LENGTH_LONG).show();
}
@Override
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this, "取消了", Toast.LENGTH_LONG).show();
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
UMShareAPI.get(this).onActivityResult(requestCode,resultCode,data);
}
@Override
protected void onDestroy() {
super.onDestroy();
UMShareAPI.get(this).release();
}
@Override
public void onSuccess(String result) {
Toast.makeText(this,result,Toast.LENGTH_SHORT).show();
}
@Override
public void onFailer(String msg) {
Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
}
}
bean類
public class LoginUser {
/**
* error : false
* results : [{"_id":"5b6bad449d21226f45755582","createdAt":"2018-08-09T10:56:04.962Z","desc":"2018-08-09","publishedAt":"2018-08-09T00:00:00.0Z","source":"web","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqgy1fu39hosiwoj30j60qyq96.jpg","used":true,"who":"lijinshanmx"},{"_id":"5b67b7fd9d2122195bdbd806","createdAt":"2018-08-06T10:52:45.809Z","desc":"2018-08-06","publishedAt":"2018-08-06T00:00:00.0Z","source":"api","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg","used":true,"who":"lijinshan"},{"_id":"5b63cd4e9d21225e0d3f58c9","createdAt":"2018-08-03T11:34:38.672Z","desc":"2018-08-03","publishedAt":"2018-08-03T00:00:00.0Z","source":"api","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqgy1ftwcw4f4a5j30sg10j1g9.jpg","used":true,"who":"lijinshan"},{"_id":"5b6151509d21225206860f08","createdAt":"2018-08-01T14:21:04.556Z","desc":"2018-08-01","publishedAt":"2018-08-01T00:00:00.0Z","source":"api","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqly1ftu6gl83ewj30k80tites.jpg","used":true,"who":"lijinshan"},{"_id":"5b60356a9d212247776a2e0e","createdAt":"2018-07-31T18:09:46.825Z","desc":"2018-07-31","publishedAt":"2018-07-31T00:00:00.0Z","source":"api","type":"福利","url":"http://ww1.sinaimg.cn/large/0065oQSqgy1ftt7g8ntdyj30j60op7dq.jpg","used":true,"who":"lijinshan"},{"_id":"5b5e93499d21220fc64181a9","createdAt":"2018-07-30T12:25:45.937Z","desc":"2018-07-30","publishedAt":"2018-07-30T00:00:00.0Z","source":"web","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqgy1ftrrvwjqikj30go0rtn2i.jpg","used":true,"who":"lijinshanmx"},{"_id":"5b50107f421aa917a31c0565","createdAt":"2018-07-19T12:15:59.226Z","desc":"2018-07-19","publishedAt":"2018-07-19T00:00:00.0Z","source":"web","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqly1ftf1snjrjuj30se10r1kx.jpg","used":true,"who":"lijinshanmx"},{"_id":"5b4eaae4421aa93aa99bee16","createdAt":"2018-07-18T11:14:55.648Z","desc":"2018-07-18","publishedAt":"2018-07-18T00:00:00.0Z","source":"web","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqly1ftdtot8zd3j30ju0pt137.jpg","used":true,"who":"lijinshanmx"},{"_id":"5b481d01421aa90bba87b9ae","createdAt":"2018-07-13T11:31:13.266Z","desc":"2018-07-13","publishedAt":"2018-07-13T00:00:00.0Z","source":"web","type":"福利","url":"http://ww1.sinaimg.cn/large/0073sXn7ly1ft82s05kpaj30j50pjq9v.jpg","used":true,"who":"lijinshanmx"},{"_id":"5b456f5d421aa92fc4eebe48","createdAt":"2018-07-11T10:45:49.246Z","desc":"2018-07-11","publishedAt":"2018-07-11T00:00:00.0Z","source":"web","type":"福利","url":"https://ww1.sinaimg.cn/large/0065oQSqly1ft5q7ys128j30sg10gnk5.jpg","used":true,"who":"lijinshanmx"}]
*/
private boolean error;
private List<ResultsBean> results;
public boolean isError() {
return error;
}
public void setError(boolean error) {
this.error = error;
}
public List<ResultsBean> getResults() {
return results;
}
public void setResults(List<ResultsBean> results) {
this.results = results;
}
public static class ResultsBean {
/**
* _id : 5b6bad449d21226f45755582
* createdAt : 2018-08-09T10:56:04.962Z
* desc : 2018-08-09
* publishedAt : 2018-08-09T00:00:00.0Z
* source : web
* type : 福利
* url : https://ww1.sinaimg.cn/large/0065oQSqgy1fu39hosiwoj30j60qyq96.jpg
* used : true
* who : lijinshanmx
*/
private String _id;
private String createdAt;
private String desc;
private String publishedAt;
private String source;
private String type;
private String url;
private boolean used;
private String who;
public String get_id() {
return _id;
}
public void set_id(String _id) {
this._id = _id;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(String publishedAt) {
this.publishedAt = publishedAt;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public boolean isUsed() {
return used;
}
public void setUsed(boolean used) {
this.used = used;
}
public String getWho() {
return who;
}
public void setWho(String who) {
this.who = who;
}
}
}
TwoAdapter類
public class TwoAdapter extends RecyclerView.Adapter<TwoAdapter.MyViewHolder>{
private Context mcontext;
private List<LoginUser.ResultsBean> list;
private RecycleitemClick click;
public void setClick(RecycleitemClick click) {
this.click = click;
}
public TwoAdapter(Context context, List<LoginUser.ResultsBean> list) {
this.mcontext=context;
this.list=list;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view=LayoutInflater.from(mcontext).inflate(R.layout.item,viewGroup,false);
MyViewHolder holder = new MyViewHolder(view, click);
return holder;
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int i) {
LoginUser.ResultsBean bean = list.get(i);
Picasso.with(mcontext).load(bean.getUrl()).into(holder.image9);
}
@Override
public int getItemCount() {
return list==null?0:list.size();
}
public interface RecycleitemClick{
void onItemClick(View view,int position);
}
public void addData(int position){
list.add(1,list.get(position));
notifyItemInserted(position);
}
public void removeData(int positoin){
list.remove(0);
notifyItemRemoved(positoin);
notifyDataSetChanged();
}
class MyViewHolder extends RecyclerView.ViewHolder{
ImageView image9;
public MyViewHolder(View itemView,final RecycleitemClick click) {
super(itemView);
image9 = itemView.findViewById(R.id.image9);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
click.onItemClick(view,getAdapterPosition());
}
});
}
}
}
LoginCallBack類
public interface LoginCallBack {
void onLoginSuccess(String result);
void onLoginFailer(String msg);
}
OkHttp類
public class OkHttp {
public void liu(String url, final HttpCallback callback) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.get()
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
int code = response.code();
if (code == 200) {
ResponseBody body = response.body();
String string = body.string();
callback.setData(string);
}
}
});
}
public interface HttpCallback {
void setData(String s);
void getData(List<LoginUser.ResultsBean> list);
}
}
LoginModel類
public class LoginModel {
public void login(final String name, final String sex, final LoginCallBack callBack){
new AsyncTask<String,Void,String>(){
@Override
protected String doInBackground(String... strings) {
if (name.contains("111")&&sex.contains("111")){
return "成功";
}else{
return "失敗";
}
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if (s.contains("成功")){
callBack.onLoginSuccess("成功");
}else{
callBack.onLoginFailer("失敗");
}
}
}.execute();
}
}
ToModel類
public class ToModel {
public void two(String path, final OkHttp.HttpCallback callback){
OkHttp okHttp = new OkHttp();
okHttp.liu(path, new OkHttp.HttpCallback() {
@Override
public void setData(String s) {
Gson gson = new Gson();
LoginUser user = gson.fromJson(s, LoginUser.class);
List<LoginUser.ResultsBean> results = user.getResults();
callback.getData(results);
}
@Override
public void getData(List<LoginUser.ResultsBean> list) {
}
});
}
}
LoginPresenter類
public class LoginPresenter {
private LoginView mloginView;
private final LoginModel mloginModel;
public LoginPresenter(LoginView mloginView) {
this.mloginView = mloginView;
mloginModel = new LoginModel();
}
public void login(String name,String sex){
mloginModel.login(name, sex, new LoginCallBack() {
@Override
public void onLoginSuccess(String result) {
mloginView.onSuccess(result);
}
@Override
public void onLoginFailer(String msg) {
mloginView.onFailer(msg);
}
});
}
}
TwoPresent類
public class TwoPresent {
private TwoView mtwoView;
private ToModel mtoModel;
public TwoPresent(TwoView mtwoView) {
this.mtwoView = mtwoView;
mtoModel = new ToModel();
}
public void two(String path) {
mtoModel.two(path, new OkHttp.HttpCallback() {
@Override
public void setData(String s) {
}
@Override
public void getData(List<LoginUser.ResultsBean> list) {
mtwoView.onGetData(list);
}
});
}
}
UrlUtil類
public String Gong = "https://gank.io/api/data/福利/10/2";
LoginView類
public interface LoginView {
void onSuccess(String result);
void onFailer(String msg);
}
TwoView類
public interface TwoView {
void onSuccess(String result);
void onFailer(String msg);
void onGetData(List<LoginUser.ResultsBean> list);
}
WXEntryActivity類
public class WXEntryActivity extends WXCallbackActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wxentry);
}
}
APP類在清單檔案註冊
public class App extends Application{
@Override
public void onCreate() {
super.onCreate();
UMConfigure.init(this,"5a12384aa40fa3551f0001d1"
,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0
UMConfigure.setLogEnabled(true);
PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0");
PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
}
}
TwoActivity類
public class TwoActivity extends AppCompatActivity implements TwoView {
private RecyclerView recycle;
private Button btn4;
private Button btn5;
private TextView text0;
private ImageView mimageView;
private TwoPresent twoPresent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
recycle = findViewById(R.id.recycle);
btn4 = findViewById(R.id.btn4);
btn5 = findViewById(R.id.btn5);
text0 = findViewById(R.id.text0);
Intent intent = getIntent();
String iconurl = intent.getStringExtra("iconurl");
String name = intent.getStringExtra("name");
text0.setText(name);
mimageView = findViewById(R.id.image);
mimageView.setVisibility(View.VISIBLE);
Picasso.with(TwoActivity.this).load(iconurl).into(mimageView);
twoPresent = new TwoPresent(this);
twoPresent.two(UrlUtil.Gong);
layout(false, true);
}
@Override
public void onSuccess(String result) {
Toast.makeText(TwoActivity.this, "成功了", Toast.LENGTH_LONG).show();
}
@Override
public void onFailer(String msg) {
Toast.makeText(TwoActivity.this, "失敗了", Toast.LENGTH_LONG).show();
}
@Override
public void onGetData(final List<LoginUser.ResultsBean> list) {
runOnUiThread(new Runnable() {
@Override
public void run() {
final TwoAdapter adapter = new TwoAdapter(getApplicationContext(), list);
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recycle.setLayoutManager(staggeredGridLayoutManager);
recycle.setAdapter(adapter);
adapter.setClick(new TwoAdapter.RecycleitemClick() {
@Override
public void onItemClick(View view, int position) {
Toast.makeText(TwoActivity.this, position + "", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(TwoActivity.this, ThreeActivity.class);
intent.putExtra("image", list.get(position).getUrl());
startActivity(intent);
}
});
btn4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
adapter.addData(1);
}
});
btn5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (list.size() > 1) {
adapter.removeData(0);
} else {
Toast.makeText(getApplication(), "沒有資料", Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
public void layout(boolean a, boolean b) {
}
}
ThreeActivity類
public class ThreeActivity extends AppCompatActivity {
private ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_three);
image = findViewById(R.id.image4);
Intent intent = getIntent();
String image1 = intent.getStringExtra("image");
Picasso.with(getApplicationContext()).load(image1).into(image);
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationY", 200);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(view, "rotation", 360);
ObjectAnimator animator4 = ObjectAnimator.ofFloat(view, "scaleX", 2, 1);
AnimatorSet set = new AnimatorSet();
set.playTogether(animator1, animator2, animator3, animator4);
set.setDuration(3000);
set.start();
}
});
}
}
two佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".TwoActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image"
android:visibility="gone"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text0"
android:gravity="center_horizontal"
android:layout_weight="1"
android:text="登入"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycle"
android:layout_marginTop="15dp"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn4"
android:layout_weight="1"
android:text="新增"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/btn5"
android:layout_weight="1"
android:text="刪除"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
three佈局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ThreeActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/image4"
tools:srcCompat="@tools:sample/avatars"
/>
</android.support.constraint.ConstraintLayout>
item佈局
<?xml version="1.0" encoding="utf-8"?>
<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">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image9"
tools:srcCompat="@tools:sample/avatars"
/>
</LinearLayout>