无法使我的圆形菜单看起来像提供的图像

问题描述

我找不到帮助我在 Wearable RecyclerView 中创建菜单的教程。弹出的所有内容都与手机的Recyclerview 相关。所以我在问可穿戴版本是否以相同的方式工作?

我遵循了文档中的内容,但我不知道如何添加项目,这样我最终会得到这样的结果:

enter image description here

编辑:

所以在搞了一些事情并在这里看到 Recyclerview代码之后:https://codinginflow.com/tutorials/android/simple-recyclerview-java/part-2-adapter(顺便说一句非常有帮助)

我设法创建了一个项目列表。问题是它们垂直排列,它们之间有很大的空间。我已经在文档中放置了应该像图像中一样排列的代码行,但我不知道问题是什么。

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Adapter;
import android.widget.Button;

import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.linearlayoutmanager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.wear.ambient.AmbientModeSupport;
import androidx.wear.widget.Wearablelinearlayoutmanager;
import androidx.wear.widget.WearableRecyclerView;

import java.util.ArrayList;
import java.util.List;

public class circular_menu_external extends FragmentActivity
        implements AmbientModeSupport.AmbientCallbackProvider,MenuItem.OnMenuItemClickListener {

//    Fragment toolsfragment = new Tools();
//    Fragment modesfragment = new Modes();
//    Fragment keysfragment = new Keys();
//    Fragment flowratefragment = new Flowrates();
  private WearableRecyclerView wearableRecyclerView;
  private Button btn;

    private ArrayList<ExampleItem> mExampleList;
    private RecyclerView.Adapter mAdapter;
    private WearableRecyclerView.LayoutManager mLayoutManager;

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

        wearableRecyclerView = findViewById(R.id.main_recycler_view);
        mAdapter = new MenuRecyclerViewAdapter(mExampleList);
        //Create a curved layout
        CustomScrollingLayoutCallback customScrollingLayoutCallback = new CustomScrollingLayoutCallback();
//        Wearablelinearlayoutmanager wearablelinearlayoutmanager = new Wearablelinearlayoutmanager(this);
//        wearableRecyclerView.setLayoutManager(wearablelinearlayoutmanager);
//        CustomScrollingLayoutCallback customScrollingLayoutCallback = new CustomScrollingLayoutCallback();
        wearableRecyclerView.setLayoutManager(
                new Wearablelinearlayoutmanager(this,customScrollingLayoutCallback));

//        wearableRecyclerView.setLayoutManager(new Wearablelinearlayoutmanager(this));
        wearableRecyclerView.setEdgeItemsCenteringEnabled(true);

        createExampleList();
        buildrecyclerView();
//////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////


    }

    private void action_1() {
        Intent i1 = new Intent(circular_menu_external.this,Settings.class);
        startActivity(i1);
    }
    private void action_2(){
        Intent i1 = new Intent(circular_menu_external.this,tool1mode1.class);
        startActivity(i1);
    }
    private void action_3(){
        Intent i1 = new Intent(circular_menu_external.this,tool1mode2.class);
        startActivity(i1);
    }
    private void action_4(){
        Intent i1 = new Intent(circular_menu_external.this,tool1mode3.class);
        startActivity(i1);
    }
    private void cancelMenu(){
        Intent i1 = new Intent(circular_menu_external.this,Main_menu.class);
        startActivity(i1);
    }


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

    @Override
    public AmbientModeSupport.AmbientCallback getAmbientCallback() {
        return null;
    }

    public void createExampleList() {
        mExampleList = new ArrayList<>();
        mExampleList.add(new ExampleItem(R.drawable.tool_ic,"Line 1","Line 2"));
        mExampleList.add(new ExampleItem(R.drawable.mode_ic,"Line 3","Line 4"));
        mExampleList.add(new ExampleItem(R.drawable.key,"Line 5","Line 6"));
        mExampleList.add(new ExampleItem(R.drawable.flow_ic,"Line 7","Line 8"));
    }
    public void buildrecyclerView() {

        wearableRecyclerView.setEdgeItemsCenteringEnabled(true);
        wearableRecyclerView.setHasFixedSize(true);
        wearableRecyclerView.setEdgeItemsCenteringEnabled(true);
        mLayoutManager = new linearlayoutmanager(this);
        mAdapter = new MenuRecyclerViewAdapter(mExampleList);
        wearableRecyclerView.setLayoutManager(mLayoutManager);
        wearableRecyclerView.setAdapter(mAdapter);


        //Add a circular scrolling gesture
        wearableRecyclerView.setCircularScrollingGestureEnabled(true);
        wearableRecyclerView.setBezelFraction(0.5f);
        wearableRecyclerView.setScrolldegreesPerScreen(90);
    }
    


    public class CustomScrollingLayoutCallback extends Wearablelinearlayoutmanager.LayoutCallback {
        /** How much should we scale the icon at most. */
        private static final float MAX_ICON_PROGRESS = 0.65f;

        private float progresstoCenter;

        @Override
        public void onLayoutFinished(View child,RecyclerView parent) {

            // figure out % progress from top to bottom
            float centerOffset = ((float) child.getHeight() / 2.0f) / (float) parent.getHeight();
            float yRelativetoCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;

            // normalize for center
            progresstoCenter = Math.abs(0.5f - yRelativetoCenterOffset);
            // Adjust to the maximum scale
            progresstoCenter = Math.min(progresstoCenter,MAX_ICON_PROGRESS);

            child.setScaleX(1 - progresstoCenter);
            child.setScaleY(1 - progresstoCenter);
        }
    }

}

这是适配器:

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.wear.widget.WearableRecyclerView;

import java.util.ArrayList;

public class MenuRecyclerViewAdapter extends WearableRecyclerView.Adapter<MenuRecyclerViewAdapter.ExampleViewHolder> {
    private ArrayList<ExampleItem> mExampleList;
    public static class ExampleViewHolder extends WearableRecyclerView.ViewHolder {
        public ImageView mImageView1,mImageView2,mImageView3,mImageView4;
        public ExampleViewHolder(View itemView) {
            super(itemView);
            mImageView1 = itemView.findViewById(R.id.imageView1);
            mImageView2 = itemView.findViewById(R.id.imageView2);
            mImageView3 = itemView.findViewById(R.id.imageView3);
            mImageView4 = itemView.findViewById(R.id.imageView4);
        }
    }
    public MenuRecyclerViewAdapter(ArrayList<ExampleItem> exampleList) {
        mExampleList = exampleList;

    }
    @Override
    public ExampleViewHolder onCreateViewHolder(ViewGroup parent,int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.example_item,parent,false);
        ExampleViewHolder evh = new ExampleViewHolder(v);
        return evh;
    }
    @Override
    public void onBindViewHolder(ExampleViewHolder holder,int position) {
        ExampleItem currentItem = mExampleList.get(position);
        holder.mImageView1.setimageResource(currentItem.getimageResource());
        holder.mImageView2.setimageResource(currentItem.getimageResource());
        holder.mImageView3.setimageResource(currentItem.getimageResource());
        holder.mImageView4.setimageResource(currentItem.getimageResource());

    }
    @Override
    public int getItemCount() {
        return mExampleList.size();
    }

}

我的项目的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.wear.widget.CircularProgressLayout
    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">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="4dp">

        <ImageButton
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_shape"
            android:src="@drawable/homeicon4"
            tools:ignore="MissingConstraints" />

        <ImageButton
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/round_shape"
        android:src="@drawable/bypass3"
        tools:ignore="MissingConstraints" />

        <ImageButton
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_shape"
            android:src="@drawable/dualflow3"
            tools:ignore="MissingConstraints" />

        <ImageButton
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_shape"
            android:src="@drawable/isolation3"
            tools:ignore="MissingConstraints" />
    </RelativeLayout>

</androidx.wear.widget.CircularProgressLayout>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...