-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6e6c24d
Showing
54 changed files
with
818 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
apply plugin: 'kotlin-android' | ||
|
||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion "26.0.1" | ||
defaultConfig { | ||
applicationId "net.blueness.recyclerviewtest" | ||
minSdkVersion 15 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | ||
implementation 'org.jetbrains.anko:anko-common:0.10.1' | ||
implementation 'com.android.support:appcompat-v7:26.0.1' | ||
implementation 'com.android.support:recyclerview-v7:26.0.1' | ||
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.0' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Users\Blueness\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/net/blueness/recyclerviewtest/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package net.blueness.recyclerviewtest | ||
|
||
import android.support.test.InstrumentationRegistry | ||
import android.support.test.runner.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getTargetContext() | ||
assertEquals("net.blueness.recyclerviewtest", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="net.blueness.recyclerviewtest"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.blueness.listviewtest | ||
|
||
/** | ||
* Created by Blueness on 2017/8/25. | ||
*/ | ||
|
||
class Fruit(val name: String, val imageId: Int) |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/net/blueness/recyclerviewtest/FruitAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package net.blueness.recyclerviewtest | ||
|
||
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 net.blueness.listviewtest.Fruit | ||
import org.jetbrains.anko.find | ||
|
||
/** | ||
* Created by Blueness on 2017/8/26. | ||
*/ | ||
|
||
class FruitAdapter(private val mFruitList: MutableList<Fruit>): | ||
RecyclerView.Adapter<FruitAdapter.ViewHolder>() { | ||
|
||
class ViewHolder(val view: View): RecyclerView.ViewHolder(view) { | ||
val fruitImage: ImageView = view.find(R.id.fruit_image) | ||
val fruitName: TextView = view.find(R.id.fruit_name) | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder{ | ||
val view = LayoutInflater.from(parent!!.context).inflate(R.layout.fruit_item, parent, false) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
val fruit = mFruitList.get(position) | ||
holder.fruitImage.setImageResource(fruit.imageId) | ||
holder.fruitName.setText(fruit.name) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return mFruitList.size | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
app/src/main/java/net/blueness/recyclerviewtest/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package net.blueness.recyclerviewtest | ||
|
||
import android.support.v7.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.support.v7.widget.LinearLayoutManager | ||
import android.support.v7.widget.RecyclerView | ||
import android.support.v7.widget.StaggeredGridLayoutManager | ||
import net.blueness.listviewtest.Fruit | ||
import org.jetbrains.anko.find | ||
import java.util.* | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private val fruitList: MutableList<Fruit> = arrayListOf() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
initFruitLists(); | ||
val recyclerView: RecyclerView = find(R.id.recycler_view) | ||
// val layoutManager = LinearLayoutManager(this) | ||
// layoutManager.orientation = LinearLayoutManager.HORIZONTAL | ||
val layoutManager = StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL) | ||
recyclerView.layoutManager = layoutManager | ||
val fruitAdapter = FruitAdapter(fruitList) | ||
recyclerView.adapter = fruitAdapter | ||
} | ||
|
||
private fun initFruitLists() { | ||
for (i in 0..2){ | ||
val apple = Fruit(getRandomLengthName("Apple"), R.drawable.apple_pic) | ||
fruitList.add(apple) | ||
val banana = Fruit(getRandomLengthName("Banana"), R.drawable.banana_pic) | ||
fruitList.add(banana) | ||
val orange = Fruit(getRandomLengthName("Orange"), R.drawable.orange_pic) | ||
fruitList.add(orange) | ||
val watermelon = Fruit(getRandomLengthName("Watermelon"), R.drawable.watermelon_pic) | ||
fruitList.add(watermelon) | ||
val pear = Fruit(getRandomLengthName("Pear"), R.drawable.pear_pic) | ||
fruitList.add(pear) | ||
val grape = Fruit(getRandomLengthName("Grape"), R.drawable.grape_pic) | ||
fruitList.add(grape) | ||
val pineapple = Fruit(getRandomLengthName("Pineapple"), R.drawable.pineapple_pic) | ||
fruitList.add(pineapple) | ||
val strawberry = Fruit(getRandomLengthName("Strawberry"), R.drawable.strawberry_pic) | ||
fruitList.add(strawberry) | ||
val cherry = Fruit(getRandomLengthName("Cherry"), R.drawable.cherry_pic) | ||
fruitList.add(cherry) | ||
val mango = Fruit(getRandomLengthName("Mango"), R.drawable.mango_pic) | ||
fruitList.add(mango) | ||
} | ||
} | ||
|
||
private fun getRandomLengthName(name:String): String{ | ||
val lenght = Random().nextInt(20) + 1 | ||
val builder = StringBuilder() | ||
for(i in 0..lenght){ | ||
builder.append(name + "\n") | ||
} | ||
return builder.toString() | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.