0

我正在处理表格数据。我的屏幕有 3 个标签。所有三个选项卡都是一个活动的一部分。每个选项卡都使用单独的布局进行膨胀。

我的要求是选项卡的布局之一可以动态更改。现在由于它是活动的一部分,我无法创建另一个活动。创建另一个活动将影响其他选项卡。

所以基本上,我想知道我们如何动态改变屏幕的布局。我应该使用 ViewFlipper 还是 Framelayout?

4

3 回答 3

0

我建议你使用 viewpager、actionbar(低版本的 sherlock actionbar)和 Fragments。这里有一些例子给你

  1. ViewPager 的官方文档

  2. androidsolution4u

  3. android-er.blogspot
于 2013-08-19T06:01:40.617 回答
0

为什么您不使用片段,请尝试以下链接可能会对您有所帮助..

Android 片段基础

Android 片段示例

于 2013-08-19T05:58:54.083 回答
0

对的,这是可能的:

像这样编写你的 xml 文件:

 <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="#262626"
tools:context=".MainActivity" >
<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  //design for 1st tab

</LinearLayout>
<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  //design for 2nd tab

</LinearLayout>
<LinearLayout
    android:id="@+id/linearLayout3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  //design for 3rd tab

</LinearLayout>
<LinearLayout
    android:id="@+id/footer_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#acacac"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" >

            <Button
                android:id="@+id/1stTab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="1dp"/>

            <Button
                android:id="@+id/2ndTab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_toRightOf="@+id/1stTab"
                 />

            <Button
                android:id="@+id/3rdTab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="1dp"
                android:layout_toRightOf="@+id/2ndTab"/>

        </RelativeLayout>
    </RelativeLayout>
</LinearLayout>
</RelativeLayout>

现在在您的 .java 文件中执行以下操作:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View layout1 = (View) findViewById(R.id.linearLayout1);
    View layout2 = (View) findViewById(R.id.linearLayout2);
    View layout3 = (View) findViewById(R.id.linearLayout3);
    Button menu1 = (Button) findViewById(R.id.1stTab);
    Button menu2 = (Button) findViewById(R.id.2ndTab);
    Button menu3 = (Button) findViewById(R.id.3rdTab);
    layout3.setVisibility(View.GONE);
    layout2.setVisibility(View.GONE);
    layout1.setVisibility(View.VISIBLE);
    menu1.setOnClickListener(new View.OnClickListener() {


        public void onClick(View v) {

            layout2.setVisibility(View.GONE);
            layout3.setVisibility(View.GONE);               
            layout1.setVisibility(View.VISIBLE);
     //do your rest tabbing work of 1stTab
        }
    });
     menu2.setOnClickListener(new View.OnClickListener() {


        public void onClick(View v) {

            layout1.setVisibility(View.GONE);
            layout3.setVisibility(View.GONE);               
            layout2.setVisibility(View.VISIBLE);
     //do your rest tabbing work of 2ndTab
        }
    });
     menu3.setOnClickListener(new View.OnClickListener() {


        public void onClick(View v) {

            layout1.setVisibility(View.GONE);
            layout2.setVisibility(View.GONE);               
            layout3.setVisibility(View.VISIBLE);
       //do your rest tabbing work of 3rdTab
        }
    });
 }

这可能会对您有所帮助。

于 2013-08-19T06:25:46.310 回答