当前位置: 首页 > news >正文

Android TV 开发(2)

本文来自网易云社区

作者:孙有军


首先来看看拨号界面的配置代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@color/transparent"
              android:orientation="horizontal"
              tools:context="im.yixin.home.dial.DialFragment">

    <FrameLayout
        android:id="@+id/dial_pan"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">
    </FrameLayout>

    <FrameLayout
        android:id="@+id/contact_pan"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="@dimen/gap_12_dp"
        android:layout_weight="3"></FrameLayout>
</LinearLayout>复制代码

对应的界面代码如下:

public class DialFragment extends Fragment{

    public DialFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @return A new instance of fragment DialFragment.
     */
    public static DialFragment newInstance() {
        DialFragment fragment = new DialFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_dial, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        addFragments();;
    }

    private void addFragments() {
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
        transaction.replace(R.id.dial_pan, new DialPanFragment());
        VerticalGridFragment fragment = new VerticalGridFragment();
        Bundle args = new Bundle();
        args.putInt(Extra.COLUMNS, Extra.DIAL_COLUMNS);
        fragment.setArguments(args);
        transaction.replace(R.id.contact_pan, fragment);
        transaction.commit();
    }

}复制代码


拨号界面被分成了两部分,一部分为拨号盘,一部分为联系人,分别占据了屏幕一份和三份,右边的联系人与主界面的好用共用了同一个Fragment,因此这里我们再看看接下来的两个界面,首先我们看看拨号盘的界面代码。

由于只做展示,因此代码写的很粗糙,界面直接写了N个按钮的代码,配置界面如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/white_35_transparent"
                android:clickable="true"
                android:contextClickable="true"
                android:orientation="vertical"
                tools:context="im.yixin.home.dial.DialFragment">

    <ImageView
        android:id="@+id/dial_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="@dimen/gap_20_dp"
        android:focusable="true"
        android:padding="@dimen/gap_20_dp"
        android:src="@drawable/tv_call_btn_selector"/>

    <LinearLayout
        android:id="@+id/input_num_line_1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/dial_icon"
        android:baselineAligned="false"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1"
            android:background="@drawable/keyboard_item_selector">

            <ImageView
                android:id="@+id/input_key_number_null"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:contentDescription="@string/empty"/>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1">

            <TextView
                android:id="@+id/input_key_number_0"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_centerInParent="true"
                android:background="@drawable/keyboard_item_selector"
                android:focusable="true"
                android:gravity="center"
                android:text="0"
                android:textColor="#ffffff"
                android:textSize="30sp"/>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/input_key_number_del"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_centerInParent="true"
                android:background="@drawable/keyboard_item_selector"
                android:contentDescription="@string/empty"
                android:focusable="true"
                android:scaleType="center"
                android:src="@drawable/tv_del"/>
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/input_num_line_2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/input_num_line_1"
        android:baselineAligned="false"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1">

            <TextView
                android:id="@+id/input_key_number_7"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_centerInParent="true"
                android:background="@drawable/keyboard_item_selector"
                android:focusable="true"
                android:gravity="center"
                android:text="7"
                android:textColor="#ffffff"
                android:textSize="30sp"/>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1">

            <TextView
                android:id="@+id/input_key_number_8"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_centerInParent="true"
                android:background="@drawable/keyboard_item_selector"
                android:focusable="true"
                android:gravity="center"
                android:text="8"
                android:textColor="#ffffff"
                android:textSize="30sp"/>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="80dp"
            android:layout_weight="1">

            <TextView
                android:id="@+id/input_key_number_9"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_centerInParent="true"
                android:background="@drawable/keyboard_item_selector"
                android:focusable="true"
                android:gravity="center"
                android:text="9"
                android:textColor="#ffffff"
                android:textSize="30sp"/>
        </RelativeLayout>
    </LinearLayout>复制代码



网易云免费体验馆,0成本体验20+款云产品!

更多网易研发、产品、运营经验分享请访问网易云社区



相关文章:
【推荐】 如何从“点子”落地到“执行”?—完整解析1个手游传播类mini项目的进化


相关文章:

  • 百度面试Web前端的经历,值得收藏
  • Unity配置安卓打包环境JDK和SDK下载以及配置详解
  • 删除n天前的所有目录和文件
  • 主流的消息队列MQ比较,详解MQ的4类应用场景
  • too many connections 解决方法
  • php的分层思想
  • 在aws ec2上使用root用户登录
  • nginx+tomcat+java部署总结
  • 云服务器有哪些操作系统?
  • 【对讲机的那点事】对讲机锂离子电池使用常识你了解吗?
  • vue-cli中使用v-chart及导出chart图片
  • 多研究些架构,少谈些框架(1):论微服务架构的核心概念
  • SpringMVC----使用POJO[普通的java类]对象绑定请求参数值
  • PAT乙级(Basic Level)练习题-NowCoder数列总结
  • KVO知识点
  • ----------
  • 【140天】尚学堂高淇Java300集视频精华笔记(86-87)
  • Angular数据绑定机制
  • electron原来这么简单----打包你的react、VUE桌面应用程序
  • Java反射-动态类加载和重新加载
  • Joomla 2.x, 3.x useful code cheatsheet
  • JSDuck 与 AngularJS 融合技巧
  • JWT究竟是什么呢?
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • Node 版本管理
  • npx命令介绍
  • puppeteer stop redirect 的正确姿势及 net::ERR_FAILED 的解决
  • Redis在Web项目中的应用与实践
  • ⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)
  • 安卓应用性能调试和优化经验分享
  • 纯 javascript 半自动式下滑一定高度,导航栏固定
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 前嗅ForeSpider采集配置界面介绍
  • 算法系列——算法入门之递归分而治之思想的实现
  • 推荐一个React的管理后台框架
  • 微信如何实现自动跳转到用其他浏览器打开指定页面下载APP
  • 再次简单明了总结flex布局,一看就懂...
  • scrapy中间件源码分析及常用中间件大全
  • 基于django的视频点播网站开发-step3-注册登录功能 ...
  • ​ 轻量应用服务器:亚马逊云科技打造全球领先的云计算解决方案
  • ​一文看懂数据清洗:缺失值、异常值和重复值的处理
  • ${factoryList }后面有空格不影响
  • (2009.11版)《网络管理员考试 考前冲刺预测卷及考点解析》复习重点
  • (8)Linux使用C语言读取proc/stat等cpu使用数据
  • (C#)Windows Shell 外壳编程系列9 - QueryInfo 扩展提示
  • (差分)胡桃爱原石
  • (二)WCF的Binding模型
  • (附源码)springboot炼糖厂地磅全自动控制系统 毕业设计 341357
  • (附源码)SSM环卫人员管理平台 计算机毕设36412
  • (原創) X61用戶,小心你的上蓋!! (NB) (ThinkPad) (X61)
  • (转)大型网站架构演变和知识体系
  • (状压dp)uva 10817 Headmaster's Headache
  • **CI中自动类加载的用法总结
  • .a文件和.so文件
  • .bat批处理出现中文乱码的情况