Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android上的底部导航-内容隐藏_Java_Android_Android Layout_Android Fragments_Android Studio 3.0 - Fatal编程技术网

Java Android上的底部导航-内容隐藏

Java Android上的底部导航-内容隐藏,java,android,android-layout,android-fragments,android-studio-3.0,Java,Android,Android Layout,Android Fragments,Android Studio 3.0,在我第一次尝试Android(Studio 3.0)时,我成功地实现了 现在,当在第一个片段上实现小部件时,我意识到底部导航覆盖/隐藏了片段的最下部 该片段由两个布局、一个listview和两个按钮组成: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="ma

在我第一次尝试Android(Studio 3.0)时,我成功地实现了

现在,当在第一个片段上实现小部件时,我意识到底部导航覆盖/隐藏了片段的最下部

该片段由两个布局、一个listview和两个按钮组成:

<FrameLayout 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"

tools:context="com.example.xyz.ticketvendor.QuickRideFragment">

<!-- TODO: Update blank fragment layout -->


 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

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

    <LinearLayout
        android:id="@+id/buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignBottom="@id/lvTransportLines">
        <Button
            android:id="@+id/getTicket"
            android:layout_width="0dp"
            android:layout_height="120dp"
            android:layout_weight=".75"
            android:text="Get Ticket" >
        </Button>
        <Button
            android:id="@+id/setDefaultSMSApp"
            android:layout_width="0dp"
            android:layout_height="120dp"
            android:layout_weight=".25"
            android:text="Reset" >
        </Button>
    </LinearLayout>
</RelativeLayout>
但我得到的结果与我第一张照片中的完全相同。我做错了什么

活动\u main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.xyz.ticketvendor.MainActivity">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginStart="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:text="@string/title_home"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>

很抱歉,我在测试一些东西,不得不从头开始创建这个示例。有趣的是,您只需对主_activity.xml文件中的FrameLayout进行一次修改

请添加以下属性,它将为您提供所需的设计

android:layout_marginBottom="?actionBarSize"
按要求更新

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.nero.myapplication.MainActivity">

<RelativeLayout
    android:id="@+id/fragment_Container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="?actionBarSize"></RelativeLayout>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="?android:attr/windowBackground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/navigation" />
}


将其添加到相对布局或框架布局中

android:layout_marginBottom="?actionBarSize"> 

将父布局设置为相对布局,将listview置于其中,然后为按钮创建线性布局(水平方向并将“对齐父底部”设置为真)。我认为是框架布局导致了overlap@Nero,我相信您的解决方案已经正确实施。。并更新了我的帖子。不知何故,它并没有解决问题:|尝试让listview高度包装内容,并共享活动的xml代码。请这样做。你能再看一眼吗在您的主活动XML文件中,将框架布局更改为线性布局(尽管它不会产生任何影响),如果这不起作用,请给我一些时间回家并解决此问题。您是否将我的更新中的代码用于新编辑的main_activity.XML?我无法复制它,伙计。我可以看看你的密码吗?谢谢真棒的工作-毫无疑问!但是有没有一种方法可以使ListView的底部位于LinearLayout的顶部之上?因为现在我无法选择按钮后面显示的列表项。(我有>25个条目)进行了更改,再次查看片段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:orientation="vertical"
tools:context="com.example.nero.myapplication.BlankFragment">



<LinearLayout
    android:id="@+id/buttons"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true">

    <Button
        android:id="@+id/getTicket"
        android:layout_width="0dp"
        android:layout_height="140dp"
        android:layout_weight=".75"
        android:text="Get Ticket"/>
    <Button
        android:id="@+id/setDefaultSMSApp"
        android:layout_width="0dp"
        android:layout_height="140dp"
        android:layout_weight=".25"
        android:text="Reset"/>

</LinearLayout>


<ListView
    android:id="@+id/lvTransportLines"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/buttons"/>
</RelativeLayout>
public class MainActivity extends AppCompatActivity {

private TextView mTextMessage;


private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
        = new BottomNavigationView.OnNavigationItemSelectedListener() {

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.navigation_home:
                mTextMessage.setText(R.string.title_home);
                return true;
            case R.id.navigation_dashboard:
                mTextMessage.setText(R.string.title_dashboard);
                return true;
            case R.id.navigation_notifications:
                mTextMessage.setText(R.string.title_notifications);
                return true;
        }
        return false;
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTextMessage = (TextView) findViewById(R.id.message);
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportFragmentManager()
            .beginTransaction()
            .add(R.id.fragment_Container, new BlankFragment(), "blankFragment")
            .disallowAddToBackStack()
            .commit();
}
android:layout_marginBottom="?actionBarSize">