进行直播app开发,ab切换环效果的实现很重要

直播app开发实现的组件交互目的很简单,就是要达到类似tab选项卡的导航栏一样,当用户点击了连续并排的若干个TextView其中之一时候,要产生一定的交互效果(背景颜色改变等)。这种实现的方式有不少可选方案,现在通过背景的selector.xml实现。

效果如下:

A。初始状态:

B。当用户单击了TextView 2,但此时用户的手指一直在按下并未松开的状态,(注意交互设计效果!TextView 2的背景颜色变成黄色):

C。用户的手指在TextView 2上松开、离开设备屏幕后的状态:

现在给出全部直播app开发实现代码。

一个非常简单的用于测试的main activity:

package zhangphil.change;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
}

重点是activity_main.xml中关于TextView的属性配置和selector.xml。

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:background="@drawable/selector"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="1" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:background="@drawable/selector"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="2" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:background="@drawable/selector"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="3" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:background="@drawable/selector"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="4" />

</LinearLayout>

每一个TextView用到的用于设置background的selector.xml。

selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/red" android:state_focused="true"/>
    <item android:drawable="@drawable/orange" android:state_pressed="true"/>
    <item android:drawable="@drawable/green"/>

</selector>

其余的就是一些直播app开发使用到的基础资源文件,图片:

green.png

red.png

orange.png

声明:本文由云豹科技转发自开开心心过博客,如有侵权请联系作者删除

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值