0

好的,所以我有一个带有 4 个标签的标签主机。这些选项卡中的每一个都有按钮,其中 2 个选项卡具有滚动视图。我的所有选项卡都托管在同一个 xml 文件中。似乎我的 xml 像脚本一样运行,因为只有我最后一个选项卡的滚动视图有效,并且只有我最后一个选项卡上的按钮有效。我准备了一份 StackOverflow 评论,其中提到将每个选项卡托管在自己的 xml 文件中,但我尝试了但没有运气。我不知道我只是没有正确编码还是什么。如果有人可以请帮助让我知道!

XML

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <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:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <RelativeLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <TextView
                    android:id="@+id/tvOffice"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Office Location"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textStyle="bold"
                    tools:ignore="HardcodedText" />

                <TextView
                    android:id="@+id/tvOfficeLocation"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvOffice"
                    android:text="Smart Technologies, Inc. is currently located at:"
                    tools:ignore="HardcodedText" />

                <TextView
                    android:id="@+id/tvOfficeAdd1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvOfficeLocation"
                    android:text="201 South Eagle Lane"
                    tools:ignore="HardcodedText" />

                <TextView
                    android:id="@+id/tvOfficeAdd2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvOfficeAdd1"
                    android:text="Smart Technologies, Inc. is currently located at:"
                    tools:ignore="HardcodedText" />

                <TextView
                    android:id="@+id/tvMap"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvOfficeAdd2"
                    android:text="View Map"
                    tools:ignore="HardcodedText" />
                <Button
                    android:id="@+id/bMap"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvMap"
                    android:text="Map"
                    tools:ignore="HardcodedText" />
                <TextView
                    android:id="@+id/tvPhone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/bMap"
                    android:text="Contact Phone Numbers"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textStyle="bold"
                    tools:ignore="HardcodedText" />

                <Button
                    android:id="@+id/bCallOffice"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvPhone"
                    android:text="Call Office"
                    tools:ignore="HardcodedText" />

                <Button
                    android:id="@+id/bCallTollFree"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/bCallOffice"
                    android:text="Call Toll Free"
                    tools:ignore="HardcodedText" />


            </RelativeLayout>

            <ScrollView
                android:id="@+id/scrollView1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <RelativeLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <ImageView
                        android:id="@+id/ivStef"
                        android:layout_width="208dp"
                        android:layout_height="208dp"
                        android:layout_alignParentLeft="true"
                        android:contentDescription="Stef"
                        android:src="@drawable/yellow_bird_icon"
                        tools:ignore="HardcodedText" />

                    <TextView
                        android:id="@+id/tvStef"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/ivStef"
                        android:text="Stephaine Smith"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold"
                        tools:ignore="HardcodedText" />

                    <TextView
                        android:id="@+id/tvStefTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tvStef"
                        android:text="Sales"
                        tools:ignore="HardcodedText" />

                    <Button
                        android:id="@+id/bCallStef"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tvStefTitle"
                        android:text="Call Stephanie"
                        tools:ignore="HardcodedText" />

                    <Button
                        android:id="@+id/bEmailStef"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/bCallStef"
                        android:text="Email Stephanie"
                        tools:ignore="HardcodedText" />

                    <ImageView
                        android:id="@+id/ivGRay"
                        android:layout_width="208dp"
                        android:layout_height="208dp"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/bEmailStef"
                        android:contentDescription="G Ray"
                        android:src="@drawable/green_bird_icon"
                        tools:ignore="HardcodedText" />

                    <TextView
                        android:id="@+id/tvGRay"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/ivGRay"
                        android:text="Gerald Ray"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold"
                        tools:ignore="HardcodedText" />

                    <TextView
                        android:id="@+id/tvGRayTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tvGRay"
                        android:text="Sales/RCDD"
                        tools:ignore="HardcodedText" />

                    <Button
                        android:id="@+id/bCallGRay"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tvGRayTitle"
                        android:text="Call Gerald"
                        tools:ignore="HardcodedText" />

                    <Button
                        android:id="@+id/bEmailGRay"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/bCallGRay"
                        android:text="Email Gerald"
                        tools:ignore="HardcodedText" />
                </RelativeLayout>
            </ScrollView>

            <RelativeLayout
                android:id="@+id/tab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <ImageView
                    android:id="@+id/ivJeremy"
                    android:layout_width="208dp"
                    android:layout_height="208dp"
                    android:layout_alignParentLeft="true"
                    android:contentDescription="Jeremy"
                    android:src="@drawable/red_bird_icon"
                    tools:ignore="HardcodedText" />

                <TextView
                    android:id="@+id/tvJeremy"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/ivJeremy"
                    android:text="Jeremy Walck"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textStyle="bold"
                    tools:ignore="HardcodedText" />

                <TextView
                    android:id="@+id/tvJeremyTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvJeremy"
                    android:text="Cabling Supervisor/ Vice President"
                    tools:ignore="HardcodedText" />

                <Button
                    android:id="@+id/bCallJeremy"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tvJeremyTitle"
                    android:text="Call Jeremy"
                    tools:ignore="HardcodedText" />

                <Button
                    android:id="@+id/bEmailJeremy"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/bCallJeremy"
                    android:text="Email Jeremy"
                    tools:ignore="HardcodedText" />
            </RelativeLayout>

            <ScrollView
                android:id="@+id/scrollView3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <RelativeLayout
                    android:id="@+id/tab4"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <ImageView
                        android:id="@+id/ivJerry"
                        android:layout_width="208dp"
                        android:layout_height="208dp"
                        android:layout_alignParentLeft="true"
                        android:contentDescription="Jerry"
                        android:src="@drawable/black_bird_icon"
                        tools:ignore="HardcodedText" />

                    <TextView
                        android:id="@+id/tvJerry"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/ivJerry"
                        android:text="Jerry Hedrick"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold"
                        tools:ignore="HardcodedText" />

                    <TextView
                        android:id="@+id/tvJerryTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tvJerry"
                        android:text="Network Administrator / Vice Presedent"
                        tools:ignore="HardcodedText" />

                    <Button
                        android:id="@+id/bCallJerry"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tvJerryTitle"
                        android:text="Call Jerry"
                        tools:ignore="HardcodedText" />

                    <Button
                        android:id="@+id/bEmailJerry"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/bCallJerry"
                        android:text="Email Jerry"
                        tools:ignore="HardcodedText" />

                    <ImageView
                        android:id="@+id/ivTanner"
                        android:layout_width="208dp"
                        android:layout_height="208dp"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/bEmailJerry"
                        android:contentDescription="Tanner"
                        android:src="@drawable/blue_bird_icon"
                        tools:ignore="HardcodedText" />

                    <TextView
                        android:id="@+id/tvTanner"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/ivTanner"
                        android:text="Tanner Hughes"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold"
                        tools:ignore="HardcodedText" />

                    <TextView
                        android:id="@+id/tvTannerTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tvTanner"
                        android:text="Network Administrator"
                        tools:ignore="HardcodedText" />

                    <Button
                        android:id="@+id/bCallTanner"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/tvTannerTitle"
                        android:text="Call Tanner"
                        tools:ignore="HardcodedText" />

                    <Button
                        android:id="@+id/bEmailTanner"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/bCallTanner"
                        android:text="Email Tanner"
                        tools:ignore="HardcodedText" />
                </RelativeLayout>
            </ScrollView>
        </FrameLayout>
    </LinearLayout>
</TabHost>

爪哇

公共类联系人扩展活动实现 View.OnClickListener {

TabSpec specs, specs2, specs3, specs4;
Button cStef, eStef, cGRay, eGRay, cJeremy, eJeremy, cJerry, eJerry,
        cTanner, eTanner, cOffice, cTollFree, MapOffice;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    // fullScreen
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.contact);
    TabHost th = (TabHost) findViewById(R.id.tabhost);
    th.setup();
    // tab2 setup
    specs = th.newTabSpec("office");
    specs.setContent(R.id.tab1);
    specs.setIndicator("Office");
    th.addTab(specs);
    // tab2 setup
    specs2 = th.newTabSpec("sales");
    specs2.setContent(R.id.tab2);
    specs2.setIndicator("Sales");
    th.addTab(specs2);
    // tab2 setup
    specs3 = th.newTabSpec("cabling");
    specs3.setContent(R.id.tab3);
    specs3.setIndicator("Cabling");
    th.addTab(specs3);
    // tab3 setup
    specs4 = th.newTabSpec("service");
    specs4.setContent(R.id.tab4);
    specs4.setIndicator("Service");
    th.addTab(specs4);
    initialize();

}

private void initialize() {
    // TODO Auto-generated method stub
    MapOffice = (Button) findViewById(R.id.bMap);
    cOffice = (Button) findViewById (R.id.bCallOffice);
    cTollFree = (Button) findViewById (R.id.bCallTollFree);
    cStef = (Button) findViewById(R.id.bCallStef);
    eStef = (Button) findViewById(R.id.bEmailStef);
    cGRay = (Button) findViewById(R.id.bCallGRay);
    eGRay = (Button) findViewById(R.id.bEmailGRay);
    cJeremy = (Button) findViewById(R.id.bCallJeremy);
    eJeremy = (Button) findViewById(R.id.bEmailJeremy);
    cJerry = (Button) findViewById(R.id.bCallJerry);
    eJerry = (Button) findViewById(R.id.bEmailJerry);
    cTanner = (Button) findViewById(R.id.bCallTanner);
    eTanner = (Button) findViewById(R.id.bEmailTanner);


    MapOffice.setOnClickListener(this);
    cOffice.setOnClickListener(this);
    cTollFree.setOnClickListener(this);
    cStef.setOnClickListener(this);
    eStef.setOnClickListener(this);
    cGRay.setOnClickListener(this);
    eGRay.setOnClickListener(this);
    cJeremy.setOnClickListener(this);
    eJeremy.setOnClickListener(this);
    cJerry.setOnClickListener(this);
    eJerry.setOnClickListener(this);
    cTanner.setOnClickListener(this);
    eTanner.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    final Intent callOffice = new Intent(Intent.ACTION_CALL);
    callOffice.setData(Uri.parse("tel:4057877878"));

    switch (v.getId()) {
    //Tab 1
    case R.id.bMap:

        break;
    case R.id.bCallOffice:
        startActivity(callOffice);
        finish();

        break;
    case R.id.bCallTollFree:
        Intent callToll = new Intent(Intent.ACTION_CALL);
        callToll.setData(Uri.parse("tel:18006461423"));
        startActivity(callToll);
        finish();

        break;

    // Tab 2
    case R.id.bCallStef:
        startActivity(callOffice);
        finish();

        break;
    case R.id.bEmailStef:
        Intent emailStef = new Intent(Intent.ACTION_SEND);
        emailStef.putExtra(Intent.EXTRA_EMAIL,
                new String[] { "ssmith@smart-technologies.com" });
        emailStef
                .putExtra(Intent.EXTRA_TEXT,
                        "This Email was sent by the Smart Technologies Android Application");
        emailStef.setType("text/plain");

        startActivity(emailStef);
        finish();

        break;
    case R.id.bCallGRay:
        startActivity(callOffice);
        finish();

        break;
    case R.id.bEmailGRay:
        Intent emailGRay = new Intent(Intent.ACTION_SEND);
        emailGRay.putExtra(Intent.EXTRA_EMAIL,
                new String[] { "Gray@smart-technologies.com" });
        emailGRay
                .putExtra(Intent.EXTRA_TEXT,
                        "This Email was sent by the Smart Technologies Android Application");
        emailGRay.setType("text/plain");
        startActivity(emailGRay);
        finish();

        break;
    // Tab 3
    }
    switch (v.getId()) {
    case R.id.bCallJeremy:
        startActivity(callOffice);
        finish();
        break;
    case R.id.bEmailJeremy:
        Intent emailJeremy = new Intent(Intent.ACTION_SEND);
        emailJeremy.putExtra(Intent.EXTRA_EMAIL,
                new String[] { "jwalck@smart-technologies.com" });
        emailJeremy
                .putExtra(Intent.EXTRA_TEXT,
                        "This Email was sent by the Smart Technologies Android Application");
        emailJeremy.setType("text/plain");
        startActivity(emailJeremy);
        finish();

        break;

    // Tab 4
    }
    switch (v.getId()) {
    case R.id.bCallJerry:
        startActivity(callOffice);
        finish();

        break;

    case R.id.bEmailJerry:
        Intent emailJerry = new Intent(Intent.ACTION_SEND);
        emailJerry.putExtra(Intent.EXTRA_EMAIL,
                new String[] { "jhedrick@smart-technologies.com" });
        emailJerry
                .putExtra(Intent.EXTRA_TEXT,
                        "This Email was sent by the Smart Technologies Android Application");
        emailJerry.setType("text/plain");
        startActivity(emailJerry);
        finish();

        break;

    case R.id.bCallTanner:
        startActivity(callOffice);
        finish();
        break;

    case R.id.bEmailTanner:
        Intent emailTanner = new Intent(Intent.ACTION_SEND);
        emailTanner.putExtra(Intent.EXTRA_EMAIL,
                new String[] { "thughes@smart-technologies.com" });
        emailTanner
                .putExtra(Intent.EXTRA_TEXT,
                        "This Email was sent by the Smart Technologies Android Application");
        emailTanner.setType("text/plain");
        startActivity(emailTanner);
        finish();

        break;

    }

}

}

4

1 回答 1

0

多个滚动视图的问题是只有一个是可聚焦的。我曾经创建了一个带有多个滚动视图的应用程序

在按钮单击上,我像这样更改了视图的可见性和可聚焦性

public void buttonShowRankingClicked(final View v){   
    rankingScrollView.setVisibility(View.VISIBLE);
    rankingScrollView.setFocusable(true);
    rankingScrollView.setClickable(true);

    teaminfoScrollView.setVisibility(View.GONE);
    teaminfoScrollView.setFocusable(false);
    teaminfoScrollView.setClickable(false);
}

这样,另一个 ScrollView 将变得可见,您可以滚动:)

于 2013-01-06T19:30:50.060 回答