Навигация не показывает второй макет XML - PullRequest
0 голосов
/ 26 августа 2018

Я постепенно изучаю процесс создания приложения в Android Studio и в настоящее время создаю приложение Android Wear с блоком навигации.

У меня есть два макета (activity_main.xml, firstexercise) с различным содержанием в каждом макете и два вида деятельности (MainActivity.java, ExerciseScreen.java). Я не могу найти какую-либо другую ссылку или ссылку из одного из файлов на другой, который я не настроил, чтобы он соответствовал именам файлов. Я также убедился, что оба Java-класса представлены в AndroidManifest.xml.

Однако, если я помещу приложение в свои умные часы, я могу видеть только макет первого экрана (activity_main.xml & MainActivity.java), но не второй макет после прокрутки вверх, чтобы увидеть содержимое нижнего ящика.

Может быть, нужно реализовать метод, который заставляет ящик переключаться на новый макет после прокрутки нижнего ящика?

Честно говоря, я хотел начать с первых шагов в разработке приложений для Android, но после того, как приложение с единственным работающим экраном (что я делал на часах), на самом деле, в основном, это навигация (ко второй странице или так). Большинство уроков не помогли мне с этой проблемой, поэтому я надеюсь, что кто-то из вас знает, чего не хватает, чтобы показать второй макет на второй странице (упражнение).

Заранее спасибо!

Вот файлы, с которыми я работаю:

MainActivity.java

[...]
public class MainActivity extends WearableActivity implements MenuItem.OnMenuItemClickListener {

    private TextView mTextView;
    private WearableDrawerLayout mWearableDrawerLayout;
    private WearableNavigationDrawerView mWearableNavigationDrawer;
    private WearableActionDrawerView mWearableActionDrawer;

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

        mTextView = (TextView) findViewById(R.id.text);

        // Enables Always-on
        setAmbientEnabled();

        // Top navigation drawer
        mWearableNavigationDrawer = (WearableNavigationDrawerView) findViewById(R.id.top_drawer);
        mWearableNavigationDrawer.setAdapter(new YourImplementationNavigationAdapter(this) {
            @Override
            public CharSequence getItemText(int i) {
                return null;
            }

            @Override
            public Drawable getItemDrawable(int i) {
                return null;
            }

            @Override
            public int getCount() {
                return 0;
            }
        });
        // Peeks navigation drawer on the top.
        //mWearableNavigationDrawer.getController().peekDrawer();
        // Bottom action drawer
        mWearableActionDrawer = (WearableActionDrawerView) findViewById(R.id.bottom_action_drawer);
        // Peeks action drawer on the bottom.
        mWearableActionDrawer.getController().peekDrawer();
        mWearableActionDrawer.setOnMenuItemClickListener(this);
    }

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        return false;}
}

ExerciseScreen.java

[...]

public class ExerciseScreen extends MainActivity{

    private WearableNavigationDrawerView mWearableNavigationDrawer;

    //View myView;
    @Override
    //public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.firstexercise);

        mWearableNavigationDrawer = (WearableNavigationDrawerView) findViewById(R.id.top_drawer);
        mWearableNavigationDrawer.setAdapter(new YourImplementationNavigationAdapter(this) {
            @Override
            public CharSequence getItemText(int i) {
                return null;
            }

            @Override
            public Drawable getItemDrawable(int i) {
                return null;
            }

            @Override
            public int getCount() {
                return 0;
            }
        });


        //myView = getLayoutInflater().inflate(R.layout.firstexercise, container, false);
    }
        //return myView;

}

AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.test.malte.gymcompanionwatch1">

    <uses-feature android:name="android.hardware.type.watch" />

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@android:style/Theme.DeviceDefault">
        <uses-library
            android:name="com.google.android.wearable"
            android:required="true" />
        <!--
               Set to true if your app is Standalone, that is, it does not require the handheld
               app to run.
        -->
        <meta-data
            android:name="com.google.android.wearable.standalone"
            android:value="true" />

        <activity
            android:name=".MainActivity"
            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=".ExerciseScreen"
            android:label="title_activity_second_activity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/dark_blue"
    android:padding="@dimen/box_inset_layout_padding"
    tools:context=".MainActivity"
    tools:deviceIds="wear">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/inner_frame_layout_padding"
        app:boxedEdges="all">

        <TextView
            android:id="@+id/text"
            android:layout_width="205dp"
            android:layout_height="wrap_content"
            android:text="@string/gymcompVersion"
            android:textSize="12sp" />
        <!-- android:text="@string/hello_world"
            //tools:text="Hey there" /> -->

    </FrameLayout>

    <android.support.wear.widget.drawer.WearableDrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ScrollView
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:nestedScrollingEnabled="true">
            <LinearLayout
                android:id="@+id/linear_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" />
        </ScrollView>
    <android.support.wear.widget.drawer.WearableNavigationDrawerView
        android:id="@+id/top_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:navigationStyle="multiPage"/>
    <android.support.wear.widget.drawer.WearableActionDrawerView
        android:id="@+id/bottom_action_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/grey"/>
            <!--app:actionMenu="@menu/action_drawer_menu"/-->


    </android.support.wear.widget.drawer.WearableDrawerLayout>

</android.support.wear.widget.BoxInsetLayout>

и наконец firstexercise.xml (хотя я мог бы назвать его как ExerciseScreen)

<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/grey"
    android:padding="@dimen/box_inset_layout_padding"
    tools:context=".ExerciseScreen"
    tools:deviceIds="wear">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/inner_frame_layout_padding"
        app:boxedEdges="all">

        <TextView
            android:id="@+id/exercisename"
            android:layout_width="205dp"
            android:layout_height="wrap_content"
            android:text="@string/firstexercisepush"
            android:textAlignment="center"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/exercisesets"
            android:layout_width="205dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="25dp"
            android:layout_marginTop="@dimen/screen_percentage_12"
            android:text="%2d Sätze"
            android:textAlignment="center"
            android:textSize="18sp" />

        <Button
            android:id="@+id/lessrepetitions"
            style="?android:attr/spinnerStyle"
            android:layout_width="46dp"
            android:layout_height="wrap_content"
            android:rotation="90"
            android:scaleX="3"
            android:scaleY="3"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="50dp" />

        <Button
            android:id="@+id/lessweight"
            style="?android:attr/spinnerStyle"
            android:layout_width="46dp"
            android:layout_height="wrap_content"
            android:rotation="90"
            android:scaleX="3"
            android:scaleY="3"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="110dp"
            />
        <!-- android:text="@string/hello_world"
            //tools:text="Hey there" /> -->

    </FrameLayout>

    <android.support.wear.widget.drawer.WearableDrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ScrollView
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:nestedScrollingEnabled="true">
            <LinearLayout
                android:id="@+id/linear_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" />
        </ScrollView>
        <android.support.wear.widget.drawer.WearableNavigationDrawerView
            android:id="@+id/top_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:navigationStyle="multiPage"/>

        <android.support.wear.widget.drawer.WearableActionDrawerView
            android:id="@+id/bottom_action_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/grey" >

        </android.support.wear.widget.drawer.WearableActionDrawerView>
        <!--app:actionMenu="@menu/action_drawer_menu"/-->


    </android.support.wear.widget.drawer.WearableDrawerLayout>

</android.support.wear.widget.BoxInsetLayout>
...