Android Studio中隐藏的操作栏

时间:2018-10-27 17:59:28

标签: android android-studio listview tabs

我正在构建一个具有3个页面要显示的应用程序。为此,我正在使用选项卡式活动。

我的选项卡式活动可以很好地与文本视图,按钮等配合使用。通过良好的操作,我的意思是我可以随时看到选项卡栏,并且可以在各个选项卡之间导航。

现在,我正在尝试在其中一个标签内填充列表视图。此列表视图使用我构建的自定义行。我在启动时使用arraylist和适配器填充此listview,然后显示它。

现在,问题在于,只要列表视图使用我的自定义行(routelistingrow.xml)填充页面,列表视图就会立即接管活动全屏并覆盖选项卡栏,并且应用程序将卡在此列表视图中。 / p>

然后,我尝试使用基本活动(没有任何标签)执行这些步骤,只是为了查看列表视图是否停留在正确的位置并避免控制屏幕。这样就可以了,操作栏始终可见。

问题是当我尝试在许多页面之一中显示此列表视图时。

我将此视频用作标签

https://www.youtube.com/watch?v=ediklbippkA

我还尝试在导航抽屉而不是选项卡中使用片段,但是仍然遇到相同的问题。

所以我想知道是什么引起了这个问题,以及为什么当我尝试从main填充listview时为什么listview会以这种方式起作用。

我还发现当我尝试在单击按钮时动态添加行时会发生此问题

我将Main2Activity保留为默认值,并添加了以下内容:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
 setContentView(R.layout.tab_routelistings);
        listView = findViewById(R.id.routelistingslistview);
        dataModels= new ArrayList<>();

        dataModels.add(new RouteTemplate("Canada", "USA"));
        dataModels.add(new RouteTemplate("USA", "Canda"));
        dataModels.add(new RouteTemplate("Canada", "USA"));
        dataModels.add(new RouteTemplate("USA", "Canda"));        
        dataModels.add(new RouteTemplate("Canada", "USA"));
        dataModels.add(new RouteTemplate("USA", "Canda"));


    adapter = new RouteAdapter(dataModels, getApplicationContext());



        listView.setAdapter(adapter);
}
 //i only added the switch statement within this method found in main2activity.

    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).

            switch(position)
            {
                case 0:
                    TabRouteListings tabRouteListings =  new TabRouteListings();
                    return tabRouteListings;
                case 1:
                    TabCreateRoute tabCreateRoute =  new TabCreateRoute();
                    return tabCreateRoute;
                default:
                    TabRouteListings tabRouteListings2 =  new TabRouteListings();
                    return  tabRouteListings2;

            }
        }

TabCreateRoute.java

public class TabCreateRoute extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.tab_createroute, container, false);
        return view;
    }
}

TabRouteListings.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">

    <ListView
        android:id="@+id/routelistingslistview"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"></ListView>

</LinearLayout>

routelistingrow.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp">>

    <TextView
        android:id="@+id/txtstartaddress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="Start Address"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@android:color/black" />

    <TextView
        android:id="@+id/txtendaddress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtstartaddress"
        android:layout_marginTop="5dp"
        android:text="End Address"
        android:textColor="@android:color/black" />

    <ImageView
        android:id="@+id/item_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@android:drawable/ic_dialog_info" />


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true">

        <!--<Button-->
            <!--android:layout_width="wrap_content"-->
            <!--android:layout_height="wrap_content"-->
            <!--android:text="Modify"-->
            <!--android:textColor="@android:color/black"-->
            <!--android:textStyle="bold" />-->


        <!--<Button-->
            <!--android:layout_width="wrap_content"-->
            <!--android:layout_height="wrap_content"-->
            <!--android:text="Delete"-->
            <!--android:textAppearance="?android:attr/textAppearanceButton"-->
            <!--android:textColor="@android:color/black"-->
            <!--android:textStyle="bold" />-->


    </LinearLayout>
</RelativeLayout>

AndroidMainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ca.mcgill.ecse321.driver">

    <uses-permission android:name="android.permission.INTERNET" />

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".RegisterActivity" />
        <activity
            android:name=".Main2Activity"
            android:label="@string/title_activity_main2"
            android:theme="@style/AppTheme.NoActionBar"></activity>
    </application>

</manifest>

过去3天,我一直在为此苦苦挣扎,想知道我是否最好继续采用其他方法(以防万一您找不到解决方案)。

1 个答案:

答案 0 :(得分:0)

由于您提到的标签视图与列表视图重叠,请尝试以下解决方案

U可以将android:paddingBottom= "10dp"放在TabRouteListings.xml的根linearLayout中

并在TabRouteListings.xml的listView中更改android:layout_width="match_parent"。此更改与您的要求没有直接关系

相关问题