我正在开发一个应用程序,我应该将我的MainActivity分成两个片段。一个在右侧whitch将保持一些textEdits和按钮,一个在左侧,应该有一些滑动标签。
我已经完成了碎片部分,并在左侧片段上添加了标签,但问题是我不知道如何使标签滑动。我真的需要你的帮助。提前谢谢。
这是我到目前为止写的:
MainActivity => AppActivity.java:
package com.example.g514110.morphokitihm1;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class AppActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app);
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.main_container_1, new MainTab())
.commit();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.main_container_2, new StaticFragment())
.commit();
}
}
public static class MainTab extends Fragment {
private FragmentTabHost mTabHost;
//Mandatory Constructor
public MainTab() {
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_main_tab,container, false);
mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("fragmenta").setIndicator("Biometric operations"),
Tab1.class, null);
mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("DataBase operations"),
Tab2.class, null);
return rootView;
}
}
public static class Tab1 extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab1, container, false);
return rootView;
}
}
public static class Tab2 extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab2, container, false);
return rootView;
}
}
public static class StaticFragment extends Fragment {
private View rootView;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
rootView = inflater.inflate(R.layout.activity_static_frag, container, false);
return rootView;
}
}
}
activity_app.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent">
<FrameLayout
android:id="@+id/main_container_1"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="450dp"/>
<FrameLayout
android:id="@+id/main_container_2"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="200dp"/>
</LinearLayout>
</LinearLayout>
activity_static_frag.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Acquisition pannel-->
<RelativeLayout
android:layout_width="170dp"
android:layout_height="fill_parent"
android:background="@drawable/textview_border"
android:orientation="vertical"
android:id="@+id/relativeLayout3"
android:layout_marginLeft="68dp"
android:layout_marginStart="71dp"
android:layout_below="@+id/APLabel">
<VideoView
android:layout_width="150dp"
android:layout_height="160dp"
android:id="@+id/videoView"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"/>
<ImageButton
android:layout_width="30dp"
android:layout_height="30dp"
android:text="@string/Sacqu"
android:id="@+id/stop"
android:background="@drawable/shutdown_design"
android:src="@drawable/shutdown1"
android:layout_column="4"
android:layout_marginTop="170dp"
android:layout_marginLeft="130dp" />
<TextView
android:layout_width="150dp"
android:layout_height="27dp"
android:text=" "
android:id="@+id/msg"
android:background="#DFDFDF"
android:layout_below="@+id/videoView"
android:layout_alignRight="@+id/videoView"
android:layout_alignEnd="@+id/videoView"
android:layout_marginTop="35dp"/>
<TextView
android:layout_width="150dp"
android:layout_height="27dp"
android:text=" "
android:background="#DFDFDF"
android:id="@+id/qty"
android:layout_below="@+id/msg"
android:layout_alignLeft="@+id/msg"
android:layout_alignStart="@+id/msg"
android:layout_marginTop="10dp"/>
<ProgressBar
android:id="@+id/qtyProgressbar"
android:layout_width="150dp"
android:layout_height="20dp"
android:background="#DFDFDF"
android:max="100"
style="?android:attr/progressBarStyleHorizontal"
android:layout_below="@+id/qty"
android:layout_alignLeft="@+id/qty"
android:layout_alignStart="@+id/qty"
android:layout_marginTop="20dp"/>
</RelativeLayout>
<TextView
android:id="@+id/APLabel"
android:layout_width="106dp"
android:layout_height="15dp"
android:background="@drawable/textview_border"
android:text="@string/AP"
android:textSize="11px"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="100dp"
android:layout_marginTop="10dp"/>
</RelativeLayout>
activity_main_tab.xml:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/item_detail_container">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/realtabcontent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
tab1.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/item_detail_container">
<!--Enrollement settings-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@drawable/textview_border"
android:orientation="vertical"
android:id="@+id/linearLayout4"
android:layout_marginTop="80dp"
android:layout_marginLeft="0dp">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="@string/consolidation"
android:id="@+id/cons_ch"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="@string/SI"
android:id="@+id/save_img_ch"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="@string/SDB"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/FFOT"
android:id="@+id/frc_ch"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ST"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="5dp"
android:id="@+id/save_temp_ch"/>
<Button
android:layout_width="110dp"
android:layout_height="35dp"
android:text="@string/enroll"
android:id="@+id/enroll"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:background="@drawable/designed_buttons"/>
</LinearLayout>
<TextView
android:id="@+id/APLabel"
android:layout_width="106dp"
android:layout_height="15dp"
android:background="@drawable/textview_border"
android:text="@string/ES"
android:textSize="11px"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="65dp" />
<RelativeLayout
android:layout_width="300dp"
android:layout_height="110dp"
android:background="@drawable/textview_border"
android:orientation="horizontal"
android:id="@+id/linearLayout6"
android:layout_marginLeft="54dp"
android:layout_marginStart="54dp"
android:layout_alignTop="@+id/linearLayout4"
android:layout_toRightOf="@+id/linearLayout4"
android:layout_toEndOf="@+id/linearLayout4">
<Button
android:layout_width="110dp"
android:layout_height="35dp"
android:text="@string/verif"
android:id="@+id/verif"
android:onClick="verify"
android:layout_marginTop="10dp"
android:layout_marginLeft="180dp"
android:background="@drawable/designed_buttons"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="110dp"
android:layout_height="35dp"
android:text="@string/identify"
android:id="@+id/identify"
android:onClick="identify"
android:layout_marginTop="5dp"
android:background="@drawable/designed_buttons"
android:layout_gravity="center_horizontal"
android:layout_below="@+id/verif"
android:layout_alignLeft="@+id/verif"
android:layout_alignStart="@+id/verif" />
<ImageView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="@+id/matchingIcon"
android:background="@drawable/matching"
android:layout_marginLeft="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<TextView
android:id="@+id/MOASLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/textview_border"
android:text="@string/MOAS"
android:textSize="11px"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_above="@+id/linearLayout6"
android:layout_alignLeft="@+id/linearLayout6"
android:layout_alignStart="@+id/linearLayout6" />
</RelativeLayout>
tab2.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/item_detail_container">
<!--Database operations-->
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/storageIcon"
android:background="@drawable/stor1"
android:layout_marginTop="30dp"
android:layout_marginLeft="5dp"
android:layout_alignBottom="@+id/record"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/textview_border"
android:id="@+id/linearLayout5">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/CreatMatch"
android:background="@drawable/designed_buttons"
android:id="@+id/matcher"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/NewRecord"
android:id="@+id/record"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@string/RecordList"
android:id="@+id/record_list"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:text="@string/dbsize"
android:id="@+id/dbSize"
android:textColor="#000"
android:layout_span="2"
android:layout_above="@+id/db_size"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="@+id/db_size"
android:background="#DFDFDF"
android:layout_span="6"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</LinearLayout>