Android TV 开发(2)

叁叁肆2018-09-26 11:20

本文来自网易云社区

作者:孙有军


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

<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+款云产品! 

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



相关文章:
【推荐】 消息推送平台高可用实践(下)
【推荐】 HTTP/2部署使用