This example for you to share the Android nine Sudoku picture display of the specific code for your reference, the specific content as follows
Mainactivity.java Code:
Package siso.ninegridimg;
Import android.support.v7.app.AppCompatActivity;
Import Android.os.Bundle;
public class Mainactivity extends Appcompatactivity {
@Override
protected void OnCreate (Bundle Savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
}
Gridstyleactivity.java Code:
Package siso.ninegridimg;
Import Android.os.Bundle;
Import android.support.v7.app.AppCompatActivity;
Import Android.support.v7.widget.LinearLayoutManager;
Import Android.support.v7.widget.RecyclerView;
Import Android.support.v7.widget.Toolbar;
Import Com.jaeger.ninegridimageview.NineGridImageView;
Import COM.JAEGER.NINEGRIDIMGDEMO.R;
Import Com.jaeger.ninegridimgdemo.adapter.PostAdapter;
Import Com.jaeger.ninegridimgdemo.entity.Post;
Import java.util.ArrayList;
Import Java.util.Arrays;
Import java.util.List;
/** * Created by Jaeger on 16/2/24. * * email:chjie.jaeger@gamil.com * Github:https://github.com/laobie/public class Gridstyleactivity extends AppComp
atactivity {private Recyclerview mrvpostlister;
Private Postadapter Mnineimageadapter;
Private list<post> mpostlist; Private string[] Img_url_list = {"Http://ac-QYgvX1CC.clouddn.com/36f0523ee1888a57.jpg", "http:// Ac-qygvx1cc.clouddn.com/07915a0154ac4a64.jpg "," http://ac-QYgvX1CC.clouddn.com/9ec4bc44bfaf07Ed.jpg "," http://ac-QYgvX1CC.clouddn.com/fa85037f97e8191f.jpg "," http://ac-QYgvX1CC.clouddn.com/ De13315600ba1cff.jpg "," http://ac-QYgvX1CC.clouddn.com/15c5c50e941ba6b0.jpg "," http://ac-QYgvX1CC.clouddn.com/ 10762c593798466a.jpg "," http://ac-QYgvX1CC.clouddn.com/eaf1c9d55c5f9afd.jpg "," http://ac-QYgvX1CC.clouddn.com/
Ad99de83e1e3f7d4.jpg "," Http://ac-QYgvX1CC.clouddn.com/233a5f70512befcc.jpg ",};
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_recycler);
Setsupportactionbar ((Toolbar) Findviewbyid (R.id.toolbar));
Mrvpostlister = (Recyclerview) Findviewbyid (r.id.rv_post_list);
Mrvpostlister.setlayoutmanager (This) (new Linearlayoutmanager);
Mpostlist = new arraylist<> ();
for (int i = 0; i < i++) {list<string> imgurls = new arraylist<> ();
Imgurls.addall (Arrays.aslist (img_url_list). sublist (0, I% 9)); Post post = new post ("Am I handsome"?) Am I handsome? Am I HandsoMe? ", imgurls);
Mpostlist.add (POST);
} mnineimageadapter = new Postadapter (this, mpostlist, Ninegridimageview.style_grid);
Mrvpostlister.setadapter (Mnineimageadapter);
}
}
Fillstyleactivity.java Code:
Package siso.ninegridimg;
Import Android.os.Bundle;
Import android.support.v7.app.AppCompatActivity;
Import Android.support.v7.widget.LinearLayoutManager;
Import Android.support.v7.widget.RecyclerView;
Import Android.support.v7.widget.Toolbar;
Import Com.jaeger.ninegridimageview.NineGridImageView;
Import COM.JAEGER.NINEGRIDIMGDEMO.R;
Import Com.jaeger.ninegridimgdemo.adapter.PostAdapter;
Import Com.jaeger.ninegridimgdemo.entity.Post;
Import java.util.ArrayList;
Import Java.util.Arrays;
Import java.util.List;
/** * Created by Jaeger on 16/2/24. * * email:chjie.jaeger@gamil.com * Github:https://github.com/laobie/public class Fillstyleactivity extends AppComp
atactivity {private Recyclerview mrvpostlister;
Private Postadapter Mpostadapter;
Private list<post> mpostlist; Private string[] Img_url_list = {"Https://pic4.zhimg.com/02685b7a5f2d8cbf74e1fd1ae61d563b_xll.jpg", "https:// Pic4.zhimg.com/fc04224598878080115ba387846eabc3_xll.jpg "," Https://pic3.zhimg.com/d1750bd47b514ad62af9497bbe5bb17e_xll.jpg "," https://pic4.zhimg.com/da52c865cb6a472c3624a78490d9a3b7_xll.jpg "," Https://pic3.zhimg.com/0c149770fc2e16f4a89e6fc479272946_xll.jpg "," https://pic1.zhimg.com/ 76903410e4831571e19a10f39717988c_xll.png "," https://pic3.zhimg.com/33c6cf59163b3f17ca0c091a5c0d9272_xll.jpg "," Https://pic4.zhimg.com/52e093cbf96fd0d027136baf9b5cdcb3_xll.png "," https://pic3.zhimg.com/
F6dc1c1cecd7ba8f4c61c7c31847773e_xll.jpg ",};
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_recycler);
Setsupportactionbar ((Toolbar) Findviewbyid (R.id.toolbar));
Mrvpostlister = (Recyclerview) Findviewbyid (r.id.rv_post_list);
Mrvpostlister.setlayoutmanager (This) (new Linearlayoutmanager);
Mpostlist = new arraylist<> ();
for (int i = 0; i < i++) {list<string> imgurls = new arraylist<> ();
Imgurls.addall (Arrays.aslist (img_url_list). sublist (0, I% 9 + 1)); Post post =New Post ("Look at the picture, the word is not important.") Want to see the big picture?
Sorry I haven't done this yet (̀.̫ ́) ", imgurls);
Mpostlist.add (POST);
} mpostadapter = new Postadapter (this, mpostlist, Ninegridimageview.style_fill);
Mrvpostlister.setadapter (Mpostadapter);
}
}
Postadapter.java Code:
Package siso.ninegridimg.adapter;
Import Android.content.Context;
Import Android.support.v7.widget.RecyclerView;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.ImageView;
Import Android.widget.TextView;
Import Android.widget.Toast;
Import java.util.List;
Import SISO.NINEGRIDIMG.R;
Import Siso.ninegridimg.entity.Post;
Import Siso.nineimglib.NineGridImageView;
Import Siso.nineimglib.NineGridImageViewAdapter; public class Postadapter extends recyclerview.adapter<postadapter.postviewholder> {private Layoutinflater
Minflater;
Private list<post> mpostlist;
private int mshowstyle;
Public Postadapter (context context, list<post> postlist, int showstyle) {super ();
Mpostlist = postlist;
Minflater = Layoutinflater.from (context);
Mshowstyle = showstyle;
@Override public void Onbindviewholder (postviewholder holder, int position) {Holder.bind (Mpostlist.get (position)); } @Override Publicint GetItemCount () {return mpostlist.size (); @Override public Postviewholder Oncreateviewholder (viewgroup parent, int viewtype) {if (Mshowstyle = = Ninegridimage
View.style_fill) {return new Postviewholder (Minflater.inflate (R.layout.item_post_fill_style, parent, false));
else {return new Postviewholder (Minflater.inflate (R.layout.item_post_grid_style, parent, false));
} public class Postviewholder extends Recyclerview.viewholder {private Ninegridimageview mnglcontent;
Private TextView mtvcontent;
Private ninegridimageviewadapter<string> Madapter = new ninegridimageviewadapter<string> () {@Override protected void Ondisplayimage (context context, ImageView ImageView, String s) {Picasso.with (context). Load (s).
Holder (R.drawable.ic_default_image). into (ImageView);
@Override protected ImageView Generateimageview (context) {return Super.generateimageview (context); } @Override protected void Onitemimageclick (context context, int index, list<string> List) {toast.maketext (context, "image position are" + index, Toast.length_short). Show ();
}
};
Public Postviewholder (View Itemview) {super (Itemview);
Mtvcontent = (TextView) Itemview.findviewbyid (r.id.tv_content);
Mnglcontent = (Ninegridimageview) Itemview.findviewbyid (r.id.ngl_images);
Mnglcontent.setadapter (Madapter);
public void bind (post post) {Mnglcontent.setimagesdata (Post.getimgurllist ());
Mtvcontent.settext (Post.getcontent ());
}
}
}
Post.java Code:
Package siso.ninegridimg.entity;
Import java.util.List;
public class Post {
private String mcontent;
Private list<string> mimgurllist;
Public post () {
} public
post (String content, list<string> imgurllist) {
mcontent = content;
Mimgurllist = imgurllist;
}
Public String getcontent () {return
mcontent;
}
public void SetContent (String content) {
mcontent = content;
}
Public list<string> getimgurllist () {return
mimgurllist;
}
public void Setimgurllist (list<string> imgurllist) {
mimgurllist = imgurllist;
}
}
Activity_main.xml:
<?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:paddingbottom= "@dimen/activity_vertical_margin"
android: paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
tools:context= "siso.ninegridimg.MainActivity" >
<textview
android:layout_width= "wrap_content"
android:layout_height= "Wrap_content"
android:text= "Hello world!"/>
</RelativeLayout>
Item_post_fill_style.xml:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
xmlns:ngl=" Http://schemas.android.com/apk/res-auto "
android:layout_width=" Match_parent "
android:layout_height= "match_parent"
android:layout_margin= "8DP"
android:background= "@color/white "
android:orientation=" vertical "
android:padding=" 8DP ">
<textview
android:id=" @+id/tv_ Content "
android:layout_width=" match_parent "
android:layout_height=" Wrap_content "
android: Layout_marginbottom= "8DP"
android:textcolor= "#333333"
android:textsize= "16sp"/>
< Com.jaeger.ninegridimageview.NineGridImageView
android:id= "@+id/ngl_images"
android:layout_width= " Match_parent "
android:layout_height=" wrap_content "
ngl:imggap=" 3DP "
ngl:showstyle=" Fill "
Ngl:singleimgsize= "160DP"/>
</LinearLayout>
Item_post_grid_style.xml
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout "xmlns:android=" 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 "Android:
Layout_margin= "8DP" android:background= "@color/white" android:orientation= "vertical" android:padding= "8DP" > <textview android:id= "@+id/tv_content" android:layout_width= match_parent "android:layout_height=" wrap_content "Android:layout_marginbottom=" 8DP "android:textcolor=" "#333333" android:textsize= "16sp" tools:text= "Test text"/> <
Com.jaeger.ninegridimageview.NineGridImageView android:id= "@+id/ngl_images" android:layout_width= "Match_parent" android:layout_height= "Wrap_content" app:imggap= "3DP" app:maxsize= "-1" app:showstyle= "Grid" app:singleimgsize= " 500DP "/> </LinearLayout>
Item_single_image.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=" Wrap_content "
android: maxheight= "60DP"
android:maxwidth= "60DP"
android:orientation= "vertical" >
<imageview
Android:id= "@+id/iv_single"
android:layout_width= "wrap_content"
android:layout_height= "Wrap_content"
android:scaletype= "Fitstart"/>
</LinearLayout>
Strings.xml
<resources>
<string name= "app_name" >NineGridImg</string>
<string name= "Fill_style" ">fill style</string>
<string name= grid_style" >grid style</string>
>
Styles.xml
<resources>
<!--Base application theme.-->
<style name= "Apptheme" parent= " Theme.AppCompat.Light.DarkActionBar ">
<!--Customize your Theme here--> <item name=
" Colorprimary "> @color/colorprimary</item>
<item name=" Android:textallcaps ">false</item>
<item name= "Colorprimarydark" > @color/colorprimarydark</item>
<item name= "Coloraccent" > @color/coloraccent</item>
<item name= "Windownotitle" >true</item>
<item name= " Android:textcolor "> @color/white</item>
<item name=" Windowactionbar ">false</item>
</style>
</resources>
Androidmanifest.xml
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android=
"http://schemas.android.com/apk/res/" Android "
package=" siso.ninegridimg >
<application
android:allowbackup= "true"
Android: icon= "@mipmap/ic_launcher"
android:label= "@string/app_name"
android:supportsrtl= "true"
Android: Theme= "@style/apptheme" >
<activity android:name= ". Mainactivity ">
<intent-filter>
<action android:name=" Android.intent.action.MAIN "/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</ activity>
</application>
</manifest>
Build.gradle
Apply plugin: ' Com.android.application '
android {
compilesdkversion
buildtoolsversion "23.0.1"
defaultconfig {
ApplicationID "siso.ninegridimg"
minsdkversion targetsdkversion
1
Versionname "1.0"
}
Buildtypes {release
{
minifyenabled false
proguardfiles getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-rules.pro '}}}
dependencies {
Compile filetree ( Include: [' *.jar '], dir: ' Libs ')
testcompile ' junit:junit:4.12 '
compile ' com.android.support:appcompat-v7 : 23.0.1 '
compile ' com.android.support:recyclerview-v7:23.3.0 '
compile ' Com.squareup.picasso:picasso : 2.5.2 '
compile project (path: ': Nineimglib ')
}
Android Class Library project Nineimglib
The results of the project run as shown:
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.