androidアプリ開発初心者です
bottom navigation Activityを使用したアプリ開発する場合って、各画面のレイアウトはどのように作ればいいですか?
①従来のボタンでの画面遷移レイアウトのように各画面のレイアウトを別々のxml作成し、bottomnavigationをタップしたときに各xmlを呼び出す
②メイン画面にすべての画面分のレイアウトを記述する
①・②のどちらですか?
メイン画面のJava
package com.example.club_.music; import android.app.Activity; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomNavigationView; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.widget.TextView; //public class Main extends AppCompatActivity { public class Main extends Activity{ private TextView mTextMessage; private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.item_music: mTextMessage.setText(R.string.Music); return true; case R.id.item_folder: mTextMessage.setText(R.string.Folder); return true; } return false; } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
メイン画面のxml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:orientation="vertical" tools:context="com.example.club_.music.Main"> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <TextView android:id="@+id/message" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/activity_vertical_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_vertical_margin" android:text="@string/Music"/> </FrameLayout> <android.support.design.widget.BottomNavigationView android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="?android:attr/windowBackground" app:menu="@menu/navigation"/> </LinearLayout>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/28 11:32
2017/07/28 11:41
2017/07/28 11:50
2017/07/28 15:20