android xml 焦点,android TV 焦点选中放大效果
使用github开源项目(非常感谢作者): 这里是项目地址:https://github.com/evilbinary/TvWidget
1.个人只需要RelativeLayout 布局,所以只是用了里边的TvZorderRelativeLayout
将TvZorderRelativeLayout.class复制到项目中
public class TvZorderRelativeLayout extends RelativeLayout {
private int position = 0;
public TvZorderRelativeLayout(Context context) {
super(context);
}
public TvZorderRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this.setChildrenDrawingOrderEnabled(true);
}
public void setCurrentPosition(int pos) {
this.position = pos;
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
View focused = findFocus();
int pos = indexOfChild(focused);
if (pos >= 0 && pos < getChildCount()) {
setCurrentPosition(pos);
postInvalidate();
}
return super.dispatchKeyEvent(event);
}
@Override
protected int getChildDrawingOrder(int childCount, int i) {
View v = getFocusedChild();
int pos = indexOfChild(v);
if (pos >= 0 && pos < childCount)
setCurrentPosition(pos);
if (i == childCount - 1) {//这是最后一个需要刷新的item
return position;
}
if (i == position) {//这是原本要在最后一个刷新的item
return childCount - 1;
}
return i;//正常次序的item
}
}
这个类主要是修改了ViewGroup 的绘制顺序,解决放大布局不被后边的布局遮挡 参看:https://blog.csdn.net/liweicai137/article/details/50826596
protected int getChildDrawingOrder (int childCount, int i)
返回迭代的绘制子类索引。如果你想改变子类的绘制顺序就要重写该方法。默认返回 i 值。
提示:为了能够调用该方法,你必须首先调用setChildrenDrawingOrderEnabled(boolean)来允许子类排序。
在调用draw()方法时,将会调用getChildDrawingOrder(int childCount ,int i)方法 ViewGroup 中默认是从上绘制到下,如果有需要改变绘制的 先后的顺序,就可以从写改方法(不改变位置)
2.还有两个类 BorderView,BorderEffect 复制到项目中,这两个类主要是 边框view移动放大动画还有宽高计算等
3.使用:
1.activity_main.xml ---------TvZorderRelativeLayout作为父布局
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false" //用来定义他的子控件是否要在他应有的边界内进行绘制。 默认情况下,clipChild被设置为true
android:clipToPadding="false" //用来定义ViewGroup是否允许在padding中绘制。默认情况下,cliptopadding被设置为ture
>
android:id="@+id/test1_rl"
android:layout_width="260dp"
android:layout_height="match_parent"
android:background="@color/color1"
android:clickable="true"
android:focusable="true"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="模块1"
android:textSize="36sp"
android:textColor="@color/white"
/>
android:id="@+id/test2_rl1"
android:layout_width="200dp"
android:layout_height="140dp"
android:layout_toRightOf="@+id/mirrcast_rl"
android:background="@color/color2"
android:layout_margin="2dp"
android:clickable="true"
android:focusable="true"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="模块2"
android:textSize="36sp"
android:textColor="@color/white"
/>
...
MainActivity
public class MainActivity extends Activity implements View.OnClickListener{
RelativeLayout main;
RelativeLayout test1_rl;
RelativeLayout test2_rl1;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BorderView border = new BorderView(this);
border.setBackgroundResource(R.drawable.border_highlight);//9.png高亮框
main = (RelativeLayout) findViewById(R.id.main);
test1_rl= findViewById(R.id.test1_rl);
test2_rl1 = findViewById(R.id.test2_rl1);
...
test1_rl.setOnClickListener(this);
test2_rl1 .setOnClickListener(this);
...
border.attachTo(main);
}
android xml 焦点,android TV 焦点选中放大效果相关推荐
- android TV 焦点选中放大效果
使用github开源项目(非常感谢作者): 这里是项目地址:https://github.com/evilbinary/TvWidget 1.个人只需要RelativeLayout 布局,所以只是用了 ...
- Android TV开发 视频窗口选中放大效果的实现
先上效果图 视频模块的布局是这样的: <RelativeLayoutandroid:id="@+id/first_view_rl"android:layout_width=& ...
- android xml png,android - 使用.png文件中的形状创建xml聊天气泡 - 堆栈内存溢出
请问是否有人知道如何在下面创建聊天气泡的xml形状? 我在网上找到的唯一示例是两个单独的形状,它们在布局中作为两个单独的背景放置-三角形和矩形. 我尝试将三角形和矩形组合在一起无济于事. 三角形似乎隐 ...
- android xml文件格式,android xml 资源文件中几个格式(@ ? @* @+)的含义
一.@代表引用资源 1.引用自定义资源.格式:@[package:]type/name android:text="@string/hello" 2.引用系统资源.格式:@andr ...
- android xml配置,Android XML设置z-Index
基本上我有2个线性布局.用户单击按钮时,一个线性布局将展开或折叠.另一个将始终显示在顶部.这里是我的xml:Android XML设置z-Index android:layout_width=&quo ...
- android xml左边,Android XML – 如何将项目对齐到最左侧,中间和最右侧
您需要使用weight属性.可以把它想象成让android知道它应该给每个项目的宽度百分比. 你需要为所有3个项目设置宽度为0dip并添加权重属性 android:layout_width=" ...
- android xml animated-rotate,Android Drawable介绍
1.Drawable简介 Android系统中将可绘制对象被抽象为Drawable,不同的绘制资源对应着不同的Drawable类型.Android FrameWork提供了常用的Drawable,An ...
- android xml opacity,Android Drawable详解
前言 Drawable就是一个可画的对象,表示一种可以在Canvas上进行绘制的抽象的概念,其可能是一张(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个 ...
- android xml msgid,Android挂逼修练之行–微信聊天消息修改器插件开发详解
一.插件开发背景 昨天无意中在刷抖音的时候看到有个视频可以修改转账信息,我就觉得好奇所以就自己实现了一下,关于微信消息修改其实是个假象就是修改本地自己看到的消息,而不是真正意义上的把聊天信息修改了,但 ...
最新文章
- TickableObjects 和 ITickable
- 麦肯锡:企业数字化转型不要被技术“绑架”
- 《科学美国人》:美国应保持太空、网络、生物领域的科技优势
- 第十五章 shell正则表达式
- mongo忘记密码并删除用户
- Java如何控制用户输入的长度,用Java Applet 进行Web编程时,如何限制输入域中可输入字符的长度!解决后马上给分!!!...
- 【 Grey Hack 】万金油脚本:常见端口漏洞检测
- @Inject.@Resource.@Autowired 的区别
- MySQL删除主从表数据
- (原创)攻击方式学习之(3) - 缓冲区溢出(Buffer Overflow)
- sql server 2012 数据库还原方法
- java反汇编_Java虚拟机学习总结(3)——JDK内置工具(jps、jstack、jmap、jstat)使用详解...
- RestTemplate.exchange各种用法(包括泛型等 --全)
- 【Python】PDF转图片
- centos7.6安装lnmp环境
- 怎样才能叫高级程序员?
- java 挑战性_想接受Java挑战吗?
- 基于历史使用数据的虚拟机动态整合研究( 文献阅读与问题理解)
- Android_studio 开发简单登陆界面
- 已解决error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“: