十天冲刺之六

在完成了初步后,简单的创建三个布局

fragment_course.xml
fragment_exercises.xml
fragment_myinfo.xml

对三个模块的界面的简单布局

例如,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical">
    <LinearLayout
        android:id="@+id/ll_head"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:background="@drawable/myinfo_login_bg"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/iv_head_icon"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="75dp"
            android:src="@drawable/default_icon" />
        <TextView
            android:id="@+id/tv_user_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="10dp"
            android:text="点击登录"
            android:textColor="@android:color/white"
            android:textSize="16sp" />
    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="20dp"
        android:background="#E3E3E3" />
    <RelativeLayout
        android:id="@+id/rl_course_history"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#F7F8F8"
        android:gravity="center_vertical">
        <ImageView
            android:id="@+id/iv_course_history_icon"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="25dp"
            android:src="@drawable/course_history_icon" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="25dp"
            android:layout_toRightOf="@id/iv_course_history_icon"
            android:text="播放记录"
            android:textColor="#A3A3A3"
            android:textSize="16sp" />
        <ImageView
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="25dp"
            android:src="@drawable/iv_right_arrow" />
    </RelativeLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#E3E3E3" />
    <RelativeLayout
        android:id="@+id/rl_setting"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#F7F8F8"
        android:gravity="center_vertical">
        <ImageView
            android:id="@+id/iv_userInfo_icon"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="25dp"
            android:src="@drawable/myinfo_setting_icon" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="25dp"
            android:layout_toRightOf="@id/iv_userInfo_icon"
            android:text="设置"
            android:textColor="#A3A3A3"
            android:textSize="16sp" />
        <ImageView
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="25dp"
            android:src="@drawable/iv_right_arrow" />
    </RelativeLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#E3E3E3" />
</LinearLayout>

  只展示了一个页面的布局,建立一个f'ragment包,在里面建立相对应的三个.class文件,对三个页面进行间的的布局

package cn.edu.gdmec.android.boxuegu.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cn.edu.gdmec.android.boxuegu.R;

public class CourseFragment extends Fragment {


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_course, null);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

}
}

  接下来是关于三个f'ragment的三个界面的显示与切换

我们首先在MainActivity里把AppCompatActivity改为FragmentActivity。

public class MainActivity extends FragmentActivity implements View.OnClickListener{

  在onCreate()里面调用

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setMain();
}

 

猜你喜欢

转载自www.cnblogs.com/fly1234/p/10873462.html