有什么方法可以在 android studio 中创建 url 的预览吗?

Is there any way to create a preview of url in android studio?

我有一个应用程序可以通过 firebase 回收器适配器加载用户配置文件 URls。我想知道如何创建预览 link,就像我们在 whatsapp 中共享 link 并生成预览一样。预览将包含一张图片、一个 header 和简短的描述。提前致谢。下面是我的代码 DashboardActivity

fAuth = FirebaseAuth.getInstance();
        firebaseDatabase = FirebaseDatabase.getInstance();
        dRef = FirebaseDatabase.getInstance().getReference("Users");

        // This will display the click counts for current online user
        user = FirebaseAuth.getInstance().getCurrentUser();
        UID = user.getUid();
            dRef.child(UID).addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot snapshot) {
                    remainingClicks = String.valueOf(snapshot.child("clicksRemain").getValue(Integer.class));
                    showGigCount = String.valueOf(snapshot.child("showGigCount").getValue(Integer.class));
                    clicks.setText(remainingClicks);
                }
                @Override
                public void onCancelled(@NonNull DatabaseError error) {
                }
            });

        recyclerView = findViewById(R.id.dashboardRCV);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
      LoadData();

    }

    private void LoadData() {
        options = new FirebaseRecyclerOptions.Builder<ModelClass>()
                .setQuery(dRef, ModelClass.class)
                .build();
        adapter = new FirebaseRecyclerAdapter<ModelClass, MyViewHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNull ModelClass model) {
                //This will hide the gig if its showGigCount becomes 0
                Query query = dRef.orderByChild("showGigCount").equalTo(0);
                ValueEventListener valueEventListener = new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                        if (snapshot.exists()){
                            holder.geglink.setVisibility(View.GONE);
                        }
                    }

                    @Override
                    public void onCancelled(@NonNull DatabaseError error) {

                    }
                };
                query.addListenerForSingleValueEvent(valueEventListener);

                    if (finalClicksCount == 0){
                        holder.geglink.setText(model.getGig());
                    }else if (dRef.child("showGigCount").equals(0)){
                        holder.geglink.setVisibility(View.GONE);
                    }else{
                        holder.geglink.setText(model.getGig());
                    }

                    holder.geglink.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(model.getGig()));
                            startActivity(browserIntent);

                            finalClicksCount = Integer.parseInt(remainingClicks);
                            remaingGigShow = Integer.parseInt(showGigCount);
                            if (finalClicksCount >= 1) {
                                finalClicksCount--;
                                remaingGigShow ++;
                                clicks.setText(String.valueOf(finalClicksCount));
                                UserClicksCounts();
                                UserShowGigCounts();
                            } else if (finalClicksCount == 0){
                                zeroClicks.setVisibility(View.VISIBLE);
                            }
                        }
                    });
            }

            @NonNull
            @Override
            public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_layout, parent, false);
                return new MyViewHolder(view);
            }
        };
        adapter.startListening();
        recyclerView.setAdapter(adapter);

单行xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="wrap_content"
    android:elevation="5dp"
    app:cardCornerRadius="5dp"
    app:cardUseCompatPadding="true">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/rcvGigLink"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="@font/montserrat"
        android:gravity="center_horizontal"
        android:text="https://www.fiverr.com/share/NwPBXR"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:textSize="14sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/rcvAbout" />

    <TextView
        android:id="@+id/rcvName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="@font/montserrat"
        android:gravity="center_horizontal"
        android:text="Zeeshan"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:textSize="14sp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/rcvAbout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="@font/montserrat"
        android:gravity="center_horizontal"
        android:text="I am a user"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:textSize="14sp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/rcvName" />
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

你可以用这个 Link Preview Library

直接使用视图就可以了

<io.github.ponnamkarthik.richlinkpreview.RichLinkView
android:id="@+id/richLinkView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</io.github.ponnamkarthik.richlinkpreview.RichLinkView>