我如何得到多个标签与scrollviews在Android的正常工作? [英] how do i get multiple tab with scrollviews to work properly in android?

查看:185
本文介绍了我如何得到多个标签与scrollviews在Android的正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我有4个选项卡的tabhost。这些选项卡中的每一个都有按钮,这些选项卡2有scrollviews。我所有的标签都在同一个XML文件中主持。好像我的XML运行就像一个剧本,因为只有我最后一个选项卡的滚动型的作品,只有在我的最后一个标签工作的按钮。我准备好计算器审查,所提的托管在其自己的XML文件中的每个选项卡,但我想没有运气。我不知道如果我只是剪掉code得当还是什么。如果有人可以请帮助让我知道!

ok, so i have a tabhost with 4 tabs. each one of these tabs has buttons, 2 of these tabs have scrollviews. all of my tabs are hosted within the same xml file. it seems like my xml runs like a script because only my last tab's scrollview works and only the buttons on my last tab work. i ready a StackOverflow review that mentioned hosting each tab in its own xml file but i tried with no luck. i dont know if i just didnt code it properly or what. If someone could please help let me know!

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>

Java的

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

public class Contact extends Activity implements 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;

    }

}

}

推荐答案

有多个scrollviews的问题是,只有一个是可聚焦。
我曾经创建的应用程序与几个scrollviews

The problem with multiple scrollviews is that only one is focusable. i once created an application with several scrollviews

和上buttonclick我改变了知名度和这样的观点的可聚焦

and on a buttonclick i changed the visibility and the focusability of the view like this

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);
}

本办法其他的滚动型会得到看得见,你可以滚动:)

This way the other ScrollView will get visible and you can scroll :)

这篇关于我如何得到多个标签与scrollviews在Android的正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆