1

私はbottom navigationfragmentsをAndroid(Studio 3.0)で初めて実装しようとしました。Androidでの下部ナビゲーション - コンテンツ隠し

最初のフラグメントにウィジェットを実装すると、ボトムナビゲーションがフラグメントの最下部をオーバーレイ/隠していることがわかります。あなたは、私が2を保つのLinearLayoutを(配置するandroid:layout_alignBottom="@id/lvTransportLines"を使用しています見ることができるように

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

demonstration

断片は、2つのレイアウト、1つのListViewコントロールと2つのボタンで構成されボタン)を押します。 テスト用の高さを何か巨大に設定しているので、私はボタンしか見ることができません。

しかし、どのレイアウト属性を使ってボトムナビゲーションで隠されないようにLinearLayoutを配置することができますか?ありがとう!

更新 Neroのソリューション@実装後、私はこの思い付いた:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     tools:context="com.example.antibala.ticketvendor.QuickRideFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 

    > 

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

    <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> 
     <Button 
      android:id="@+id/setDefaultSMSApp" 
      android:layout_width="0dp" 
      android:layout_height="140dp" 
      android:layout_weight=".25" 
      android:text="Reset" 

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

しかし、私は私の最初の絵と全く同じ結果を得ることができます。何が間違っているのですか?

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.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> 
+0

、相対的なレイアウトとして、あなたの親のレイアウトを作成し、その中にあなたのリストビューを配置し、あなたのボタンののLinearLayoutを作成する(水平方向と真の親底を合わせる設定)。 フレームのレイアウトがオーバーラップしていると思います。 – Nero

+0

@Nero、私はあなたのソリューションを正しく実装していると信じています。どういうわけかそれは問題を解決しません:| – tingtong

+0

あなたのリストビューの高さをラップコンテンツにして、あなたの活動のxmlコードを共有しようとしてください。 – Nero

答えて

1

は、私は物事のカップルをテストし、最初からこの例を作成しなければなりませんでした。面白いのは、Main_activity.xmlファイルのFrameLayoutに対して1つの修正を加えるだけです。

次の属性を追加してください。希望するデザインが得られます。

android:layout_marginBottom="?actionBarSize" 
Fragment_blank.xml

要求

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

として更新

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

Main_activity.java

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

}

Result

+0

私の更新のコードを新しく編集したmain_activity.xmlで使用していますか?私はそれをバディを再現することができません。私はウルのコードを見てもいいですか?ありがとう! – tingtong

+0

あなたはプロです!ありがとう^ 10 – tingtong

+0

素晴らしい仕事 - 間違いなく! ListViewがLinearLayoutの上の下にある方法がありますか?今のところ私はボタンの背後に表示されているlistItemsを決して選択することができないので、 (私は> 25エントリを持っています) – tingtong

関連する問題