Basically it's al grey when I add the Wearable RecyclerView
, I tried adding buttons or anything but nothing appears.
How do you add it in the xml
layout file? I feel like I'm missing something. I basically added a layout in this case: wearable drawer layout and inside it I added the Wearable RecyclerView
and within it some things I want to display in the same manner as this picture--->
Below is the xml code for the layout. My app keeps crashing whenever I start this activity.
<androidx.wear.widget.drawer.WearableDrawerLayout 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/black"
android:padding="@dimen/box_inset_layout_padding"
tools:context=".circular_menu_external"
tools:deviceIds="wear">
<androidx.wear.widget.WearableRecyclerView
android:id="@+id/main_menu_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/round_shape"
android:backgroundTint="@color/Tan"
android:text="icon 1" />
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/round_shape"
android:backgroundTint="@color/Tan"
android:gravity="center"
android:text="icon 2"
android:translationY="70dp" />
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/round_shape"
android:backgroundTint="@color/Tan"
android:gravity="center"
android:text="icon 3"
android:translationY="150dp" />
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/round_shape"
android:backgroundTint="@color/Tan"
android:gravity="center"
android:text="icon 4"
android:translationX="50dp" />
</androidx.wear.widget.WearableRecyclerView>
</androidx.wear.widget.drawer.WearableDrawerLayout>
This is from my activity code:
private void onLayoutInflated()
{
CustomScrollingLayoutCallback customScrollingLayoutCallback = new CustomScrollingLayoutCallback();
wearableRecyclerView.setLayoutManager(new WearableLinearLayoutManager(circular_menu_external.this, customScrollingLayoutCallback));
wearableRecyclerView.setEdgeItemsCenteringEnabled(true);
}
private class CustomScrollingLayoutCallback extends WearableLinearLayoutManager.LayoutCallback {
private static final float MAX_ICON_PROGRESS = 2F;
@Override
public void onLayoutFinished(View child, RecyclerView parent) {
float centerOffset = ((float) child.getHeight() / 2.0f) / (float) parent.getHeight();
float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;
float progresstoCenter = (float) Math.sin(yRelativeToCenterOffset * Math.PI);
float mProgressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);
mProgressToCenter = Math.min(mProgressToCenter, MAX_ICON_PROGRESS);
child.setScaleX(1 - mProgressToCenter);
child.setScaleY(1 - mProgressToCenter);
child.setX(+(1 - progresstoCenter) * 100);
}
}
I simply call the onLayoutInflated()
method into the onCreate
method
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…