├── README.md ├── res ├── raw │ └── himi_ogg.ogg ├── drawable │ ├── bound.png │ ├── bound2.png │ ├── focus_bound.png │ ├── white_border.png │ └── white_border1.9.png ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── values-sw600dp │ └── dimens.xml ├── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── menu │ └── main.xml ├── values-sw720dp-land │ └── dimens.xml ├── values-v11 │ └── styles.xml ├── anim │ ├── box_normal.xml │ └── box_alpha.xml ├── values-v14 │ └── styles.xml └── layout │ ├── grid_item.xml │ └── activity_main.xml ├── libs ├── android-support-v4.jar └── nineoldandroids-2.4.0.jar ├── project.properties ├── AndroidManifest.xml └── src └── com └── example └── borderviewdemo ├── Utils ├── AnimUtils.java └── DensityUtil.java ├── View ├── VerticalSmoothGridView.java ├── FocusBorderView.java ├── BorderView.java └── CopyOfCopyOfFocusBorderView.java └── MainActivity.java /README.md: -------------------------------------------------------------------------------- 1 | BorderViewDemo 2 | ============== 3 | -------------------------------------------------------------------------------- /res/raw/himi_ogg.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/raw/himi_ogg.ogg -------------------------------------------------------------------------------- /res/drawable/bound.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/drawable/bound.png -------------------------------------------------------------------------------- /res/drawable/bound2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/drawable/bound2.png -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/libs/android-support-v4.jar -------------------------------------------------------------------------------- /res/drawable/focus_bound.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/drawable/focus_bound.png -------------------------------------------------------------------------------- /libs/nineoldandroids-2.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/libs/nineoldandroids-2.4.0.jar -------------------------------------------------------------------------------- /res/drawable/white_border.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/drawable/white_border.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable/white_border1.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/drawable/white_border1.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lf8289/BorderViewDemo/HEAD/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TvBorderViewDemo 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/anim/box_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/anim/box_alpha.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 16 | 17 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /res/layout/grid_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 15 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/com/example/borderviewdemo/Utils/AnimUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.borderviewdemo.Utils; 2 | 3 | import com.example.tvborderviewdemo.R; 4 | 5 | import android.content.Context; 6 | //import android.util.Log; 7 | import android.view.animation.AlphaAnimation; 8 | import android.view.animation.Animation; 9 | import android.view.animation.AnimationSet; 10 | import android.view.animation.ScaleAnimation; 11 | 12 | public class AnimUtils { 13 | 14 | private static final String TAG = "AnimUtils"; 15 | private static Animation mBoxAnimNormal; 16 | 17 | public static Animation buildAnimBoxNormal(Context context) { 18 | if (mBoxAnimNormal != null) { 19 | return mBoxAnimNormal; 20 | } 21 | mBoxAnimNormal = android.view.animation.AnimationUtils.loadAnimation( 22 | context, R.anim.box_alpha); 23 | return mBoxAnimNormal; 24 | } 25 | 26 | public static AnimationSet buildAnimBoxClick(Context context) { 27 | final ScaleAnimation scale = new ScaleAnimation(0.5f, 1.3f, 0.5f, 1.3f, 28 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 29 | 0.5f); 30 | AlphaAnimation alpha = new AlphaAnimation(0.5f, 1.0f); 31 | AnimationSet mBoxAnimClick = new AnimationSet(true); 32 | mBoxAnimClick.addAnimation(scale); 33 | mBoxAnimClick.addAnimation(alpha); 34 | mBoxAnimClick.setDuration(100); 35 | return mBoxAnimClick; 36 | } 37 | } -------------------------------------------------------------------------------- /src/com/example/borderviewdemo/Utils/DensityUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.borderviewdemo.Utils; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | 6 | /** 7 | * 分辨率转换类 8 | * 9 | * @author 李小斌 364643658@qq.com 10 | * */ 11 | public class DensityUtil { 12 | 13 | // int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); 14 | // // 屏幕宽(像素,如:480px) 15 | // int screenHeight = 16 | // getWindowManager().getDefaultDisplay().getHeight(); // 屏幕高(像素,如:800p) 17 | // int xDip = DensityUtil.px2dip(SettingActivity.this, (float) 18 | // (screenWidth * 1.0)); 19 | // int yDip = DensityUtil.px2dip(SettingActivity.this, (float) 20 | // (screenHeight * 1.0)); 21 | 22 | public static int getScreenHeight(Activity activity) { 23 | return activity.getWindowManager().getDefaultDisplay().getHeight(); 24 | } 25 | 26 | public static int getScreenWidth(Activity activity) { 27 | return activity.getWindowManager().getDefaultDisplay().getWidth(); 28 | } 29 | 30 | /** 31 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 32 | */ 33 | public static int dip2px(Context context, float dpValue) { 34 | final float scale = context.getResources().getDisplayMetrics().density; 35 | return (int) (dpValue * scale + 0.5f); 36 | } 37 | 38 | /** 39 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp 40 | */ 41 | public static int px2dip(Context context, float pxValue) { 42 | final float scale = context.getResources().getDisplayMetrics().density; 43 | return (int) (pxValue / scale + 0.5f); 44 | } 45 | } -------------------------------------------------------------------------------- /src/com/example/borderviewdemo/View/VerticalSmoothGridView.java: -------------------------------------------------------------------------------- 1 | package com.example.borderviewdemo.View; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.KeyEvent; 8 | import android.widget.GridView; 9 | 10 | public class VerticalSmoothGridView extends GridView { 11 | 12 | private final static int SCROLL_ITEM_TIME = 1500; 13 | private int eventCount = 0; 14 | private final static int DOUBLE_ROW = 2; // "2"在双数行 15 | private final static int SINGLE_ROW = 1; // "1"在单行 16 | 17 | /** 18 | * <默认构造函数> 19 | */ 20 | public VerticalSmoothGridView(Context context) { 21 | super(context); 22 | } 23 | 24 | public VerticalSmoothGridView(Context context, AttributeSet attrs, 25 | int defStyle) { 26 | super(context, attrs, defStyle); 27 | } 28 | 29 | public VerticalSmoothGridView(Context context, AttributeSet attrs) { 30 | super(context, attrs); 31 | } 32 | 33 | @Override 34 | public boolean dispatchKeyEvent(KeyEvent event) { 35 | 36 | int height = this.getChildAt(1).getHeight(); 37 | eventCount++; 38 | // 该eventCount%2 是为了取的按键的第一次,因为对不同的item,它会执行两次 39 | if (eventCount % 2 != 0) { 40 | int row = 0; 41 | row = getItemCurrentRow(); 42 | if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN 43 | && row == DOUBLE_ROW) { 44 | this.smoothScrollBy(height, SCROLL_ITEM_TIME); 45 | Log.d("", "向下..滑动执行了"); 46 | } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP 47 | && row == SINGLE_ROW) { 48 | this.smoothScrollBy(-height, SCROLL_ITEM_TIME); 49 | Log.d("", "向上..滑动执行了"); 50 | } 51 | } 52 | return super.dispatchKeyEvent(event); 53 | } 54 | 55 | /** 56 | * 57 | * 获取Gridview中当前item所在的行 58 | * 59 | * @return 60 | */ 61 | @SuppressLint("NewApi") 62 | public int getItemCurrentRow() { 63 | int row = 0; 64 | int position = 0; 65 | position = this.getSelectedItemPosition(); 66 | Log.d("", "dispatchKeyEvent..position = " + position); 67 | Log.d("", "this.getNumColumns() = " + this.getNumColumns()); 68 | int temp = (position / this.getNumColumns() + 1) % 2; 69 | if (temp == 0) { 70 | row = DOUBLE_ROW; 71 | Log.d("", "在双数行"); 72 | } else { 73 | row = SINGLE_ROW; 74 | Log.d("", "在单行"); 75 | } 76 | return row; 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 23 | 24 | 33 | 34 | 38 | 39 | 46 | 47 |