├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── carlos │ │ └── mylistview │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── carlos │ │ │ └── mylistview │ │ │ ├── MainActivity.java │ │ │ ├── MainAdapter.java │ │ │ └── MyListView.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── item_main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── carlos │ └── mylistview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | MyListView -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.carlos.mylistview" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'com.android.support:design:23.1.1' 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in f:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/carlos/mylistview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.carlos.mylistview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlos/mylistview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.carlos.mylistview; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.view.inputmethod.InputMethodManager; 8 | import android.widget.EditText; 9 | import android.widget.ListView; 10 | import android.widget.Toast; 11 | 12 | public class MainActivity extends AppCompatActivity implements MyListView.OnSizeChangedListener, View.OnClickListener { 13 | private ListView listView; 14 | private EditText editText; 15 | 16 | /** 17 | * item的高度 18 | */ 19 | private int viewHeight; 20 | /** 21 | * 当前点击的位置 22 | */ 23 | private int position; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | editText = (EditText) findViewById(R.id.editText); 30 | listView = (ListView) findViewById(R.id.listView); 31 | //因为是自定义的ListView,所以在这里设置回调 32 | ((MyListView) listView).setOnSizeChangedListener(this); 33 | listView.setAdapter(new MainAdapter(this, this)); 34 | } 35 | 36 | /** 37 | * ListView尺寸改变后的回调 38 | */ 39 | @Override 40 | public void onSizeChanged() { 41 | listView.setSelectionFromTop(position, listView.getBottom() - viewHeight); 42 | } 43 | 44 | @Override 45 | public void onClick(View v) { 46 | //获取当前点击的位置 47 | position = (int) v.getTag(); 48 | Toast.makeText(this, "点击了" + position, Toast.LENGTH_LONG).show(); 49 | //获取点击的那个Item的高度 50 | viewHeight = ((View) v.getParent()).getHeight(); 51 | editText.requestFocus(); 52 | InputMethodManager inputManager = 53 | (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); 54 | inputManager.showSoftInput(editText, 0); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlos/mylistview/MainAdapter.java: -------------------------------------------------------------------------------- 1 | package com.carlos.mylistview; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.TextView; 9 | 10 | /** 11 | * Created by Administrator on 2015/12/30. 12 | */ 13 | public class MainAdapter extends BaseAdapter { 14 | private Context context; 15 | private View.OnClickListener onClickListener; 16 | private LayoutInflater layoutInflater; 17 | 18 | public MainAdapter(Context context, View.OnClickListener onClickListener) { 19 | this.context = context; 20 | this.onClickListener = onClickListener; 21 | layoutInflater = LayoutInflater.from(context); 22 | } 23 | 24 | @Override 25 | public int getCount() { 26 | return 100; 27 | } 28 | 29 | @Override 30 | public Object getItem(int position) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public long getItemId(int position) { 36 | return position; 37 | } 38 | 39 | @Override 40 | public View getView(int position, View convertView, ViewGroup parent) { 41 | convertView = layoutInflater.inflate(R.layout.item_main, parent, false); 42 | TextView top = (TextView) convertView.findViewById(R.id.top); 43 | TextView middle = (TextView) convertView.findViewById(R.id.middle); 44 | TextView bottom = (TextView) convertView.findViewById(R.id.bottom); 45 | top.setText("这里是顶部" + position); 46 | middle.setText("这里是中间" + position); 47 | bottom.setText("这里是底部" + position + " 假设这是评论按钮"); 48 | bottom.setTag(position); 49 | bottom.setOnClickListener(onClickListener); 50 | return convertView; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlos/mylistview/MyListView.java: -------------------------------------------------------------------------------- 1 | package com.carlos.mylistview; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.ListView; 6 | 7 | /** 8 | * Created by Administrator on 2015/12/30. 9 | */ 10 | public class MyListView extends ListView { 11 | private OnSizeChangedListener onSizeChangedListener; 12 | 13 | public void setOnSizeChangedListener(OnSizeChangedListener onSizeChangedListener) { 14 | this.onSizeChangedListener = onSizeChangedListener; 15 | } 16 | 17 | interface OnSizeChangedListener { 18 | public void onSizeChanged(); 19 | } 20 | 21 | public MyListView(Context context) { 22 | super(context); 23 | } 24 | 25 | public MyListView(Context context, AttributeSet attrs) { 26 | super(context, attrs); 27 | } 28 | 29 | public MyListView(Context context, AttributeSet attrs, int defStyleAttr) { 30 | super(context, attrs, defStyleAttr); 31 | } 32 | 33 | @Override 34 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 35 | super.onSizeChanged(w, h, oldw, oldh); 36 | onSizeChangedListener.onSizeChanged(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 17 | 18 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/MyListView/c89c055d84e76b945f2efe89e710b98b7482f330/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/MyListView/c89c055d84e76b945f2efe89e710b98b7482f330/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/MyListView/c89c055d84e76b945f2efe89e710b98b7482f330/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/MyListView/c89c055d84e76b945f2efe89e710b98b7482f330/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/MyListView/c89c055d84e76b945f2efe89e710b98b7482f330/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | > 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MyListView 3 | Settings 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |