-
Notifications
You must be signed in to change notification settings - Fork 12
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
梁任彦
committed
Nov 10, 2017
0 parents
commit 602514f
Showing
47 changed files
with
1,339 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,39 @@ | ||
/captures | ||
|
||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
|
||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
/build | ||
/*/build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Eclipse project files | ||
.classpath | ||
.project | ||
.settings/ | ||
|
||
# Intellij project files | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# System files | ||
.DS_Store |
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,32 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion "26.0.1" | ||
defaultConfig { | ||
applicationId "com.donkingliang.headerviewadapterdemo" | ||
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 { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:26.+' | ||
compile 'com.android.support.constraint:constraint-layout:1.0.2' | ||
testCompile 'junit:junit:4.12' | ||
|
||
compile project(":headerviewadapter") | ||
} |
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\Administrator\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 |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/donkingliang/headerviewadapterdemo/ExampleInstrumentedTest.java
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,26 @@ | ||
package com.donkingliang.headerviewadapterdemo; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.donkingliang.headerviewadapterdemo", appContext.getPackageName()); | ||
} | ||
} |
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="com.donkingliang.headerviewadapterdemo" > | ||
|
||
<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> |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/donkingliang/headerviewadapterdemo/GridAdapter.java
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,49 @@ | ||
package com.donkingliang.headerviewadapterdemo; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
/** | ||
* Depiction: | ||
* Author:lry | ||
* Dat:2017/11/10 | ||
*/ | ||
public class GridAdapter extends RecyclerView.Adapter<GridAdapter.ViewHolder> { | ||
|
||
private Context mContext; | ||
|
||
public GridAdapter(Context context) { | ||
mContext = context; | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_goods_grid, parent, false); | ||
return new ViewHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder holder, final int position) { | ||
holder.itemView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Log.e("TAG", "position = " + position); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return 10; | ||
} | ||
|
||
static class ViewHolder extends RecyclerView.ViewHolder { | ||
ViewHolder(View itemView) { | ||
super(itemView); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/donkingliang/headerviewadapterdemo/LinearAdapter.java
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,49 @@ | ||
package com.donkingliang.headerviewadapterdemo; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
/** | ||
* Depiction: | ||
* Author:lry | ||
* Dat:2017/11/10 | ||
*/ | ||
public class LinearAdapter extends RecyclerView.Adapter<LinearAdapter.ViewHolder> { | ||
|
||
private Context mContext; | ||
|
||
public LinearAdapter(Context context) { | ||
mContext = context; | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_goods_linear, parent, false); | ||
return new ViewHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder holder, final int position) { | ||
holder.itemView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
Log.e("TAG", "position = " + position); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return 10; | ||
} | ||
|
||
static class ViewHolder extends RecyclerView.ViewHolder { | ||
ViewHolder(View itemView) { | ||
super(itemView); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/donkingliang/headerviewadapterdemo/MainActivity.java
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,52 @@ | ||
package com.donkingliang.headerviewadapterdemo; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
|
||
import com.donkingliang.headerviewadapter.HeaderViewAdapter; | ||
import com.donkingliang.headerviewadapter.HeaderViewGridLayoutManager; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private RecyclerView rvList; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
rvList = (RecyclerView) findViewById(R.id.rv_list); | ||
showLinearList(); | ||
// showGridList(); | ||
} | ||
|
||
private void showLinearList() { | ||
LinearAdapter adapter = new LinearAdapter(this); | ||
HeaderViewAdapter headerViewAdapter = new HeaderViewAdapter(adapter); | ||
rvList.setLayoutManager(new LinearLayoutManager(this)); | ||
View hv1 = LayoutInflater.from(this).inflate(R.layout.layout_header, rvList, false); | ||
View hv2 = LayoutInflater.from(this).inflate(R.layout.layout_header_view, rvList, false); | ||
View fv = LayoutInflater.from(this).inflate(R.layout.layout_footer_view, rvList, false); | ||
headerViewAdapter.addHeaderView(hv1); | ||
headerViewAdapter.addHeaderView(hv2); | ||
headerViewAdapter.addFooterView(fv); | ||
rvList.setAdapter(headerViewAdapter); | ||
} | ||
|
||
private void showGridList() { | ||
GridAdapter adapter = new GridAdapter(this); | ||
HeaderViewAdapter headerViewAdapter = new HeaderViewAdapter(adapter); | ||
rvList.setLayoutManager(new HeaderViewGridLayoutManager(this, 2, headerViewAdapter)); | ||
View hv1 = LayoutInflater.from(this).inflate(R.layout.layout_header, rvList, false); | ||
View hv2 = LayoutInflater.from(this).inflate(R.layout.layout_header_view, rvList, false); | ||
View fv = LayoutInflater.from(this).inflate(R.layout.layout_footer_view, rvList, false); | ||
headerViewAdapter.addHeaderView(hv1); | ||
headerViewAdapter.addHeaderView(hv2); | ||
headerViewAdapter.addFooterView(fv); | ||
rvList.setAdapter(headerViewAdapter); | ||
} | ||
} |
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.
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#eeeeee" | ||
android:orientation="vertical"> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/rv_list" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</LinearLayout> |
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,61 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/rl_item" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="3dp" | ||
android:background="@android:color/white"> | ||
|
||
<ImageView | ||
android:id="@+id/iv_goods" | ||
android:layout_width="match_parent" | ||
android:layout_height="177dp" | ||
android:scaleType="fitXY" | ||
android:src="@drawable/goods_image" /> | ||
|
||
<RelativeLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/iv_goods"> | ||
|
||
<TextView | ||
android:id="@+id/tv_goods_name" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="5dp" | ||
android:layout_marginRight="5dp" | ||
android:layout_marginTop="5dp" | ||
android:singleLine="true" | ||
android:text="有机西红柿番茄" | ||
android:textColor="@android:color/black" | ||
android:textSize="16sp" /> | ||
|
||
<TextView | ||
android:id="@+id/tv_price" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentRight="true" | ||
android:layout_below="@+id/tv_goods_name" | ||
android:layout_marginBottom="5dp" | ||
android:layout_marginRight="5dp" | ||
android:singleLine="true" | ||
android:text="¥32.00" | ||
android:textColor="@android:color/holo_red_dark" | ||
android:textSize="14sp" /> | ||
|
||
<TextView | ||
android:id="@+id/tv_unit" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignBottom="@+id/tv_price" | ||
android:layout_alignLeft="@+id/tv_goods_name" | ||
android:layout_marginRight="5dp" | ||
android:layout_toLeftOf="@+id/tv_price" | ||
android:singleLine="true" | ||
android:text="单位:500g/包" | ||
android:textColor="@android:color/black" | ||
android:textSize="14sp" /> | ||
|
||
</RelativeLayout> | ||
|
||
</RelativeLayout> |
Oops, something went wrong.