毕加索和滑翔都没有在我的应用中显示图像

问题描述 投票:0回答:1

我正在创建一个电影应用程序,有两个片段显示现在播放电影和即将上映的电影现在我正在创建现在播放片段,我使用item_movie布局,具有cardview作为root和relativelayout,并在这两个textview和imageview,我使用毕加索来加载图像我的问题是图像没有出现,但文本视图显示我试图找到几个小时的答案,但我没有那个让我疯狂这里是现在播放片段的代码

package com.example.moviemanager.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerViewAccessibilityDelegate;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.moviemanager.R;
import com.example.moviemanager.adapters.MovieRecyclerViewAdapter;
import com.example.moviemanager.models.Movie;

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

/**
 * A simple {@link Fragment} subclass.
 */
public class NowPlayingFragment extends Fragment {
    RecyclerView rcmovies;
    private List<Movie> movies;

    public NowPlayingFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view =inflater.inflate(R.layout.fragment_now_playing, container, false);

        initializeData();

        rcmovies= view.findViewById(R.id.rvMovies);
        LinearLayoutManager llm=new LinearLayoutManager(this.getContext());
        rcmovies.setHasFixedSize(true);
        rcmovies.setLayoutManager(llm);
        MovieRecyclerViewAdapter adapter=new MovieRecyclerViewAdapter(this.getContext(),movies);
        rcmovies.setAdapter(adapter);
        return view;

    }


    private void initializeData() {
        movies = new ArrayList<>();
        movies.add(new Movie("277834", "Moana", "In Ancient Polynesia, when a terrible curse incurred by Maui reaches an impetuous Chieftain's daughter's island, she answers the Ocean's call to seek out the demigod to set things right.", 6.5f, 854, "/z4x0Bp48ar3Mda8KiPD1vwSY3D8.jpg", "/1qGzqGUd1pa05aqYXGSbLkiBlLB.jpg"));
        movies.add(new Movie("121856", "Passengers", "A spacecraft traveling to a distant colony planet and transporting thousands of people has a malfunction in its sleep chambers. As a result, two passengers are awakened 90 years early.", 6.2f,  745, "/5gJkVIVU7FDp7AfRAbPSvvdbre2.jpg", "/5EW4TR3fWEqpKsWysNcBMtz9Sgp.jpg"));
        movies.add(new Movie("330459", "Assassin's Creed", "Lynch discovers he is a descendant of the secret Assassins society through unlocked genetic memories that allow him to relive the adventures of his ancestor, Aguilar, in 15th Century Spain. After gaining incredible knowledge and skills he’s poised to take on the oppressive Knights Templar in the present day.", 5.3f, 691, "/tIKFBxBZhSXpIITiiB5Ws8VGXjt.jpg", "/5EW4TR3fWEqpKsWysNcBMtz9Sgp.jpg"));
        movies.add(new Movie("283366", "Rogue One: A Star Wars Story", "A rogue band of resistance fighters unite for a mission to steal the Death Star plans and bring a new hope to the galaxy.", 7.2f, 1802, "/qjiskwlV1qQzRCjpV0cL9pEMF9a.jpg", "/tZjVVIYXACV4IIIhXeIM59ytqwS.jpg"));
        movies.add(new Movie("313369", "La La Land", "Mia, an aspiring actress, serves lattes to movie stars in between auditions and Sebastian, a jazz musician, scrapes by playing cocktail party gigs in dingy bars, but as success mounts they are faced with decisions that begin to fray the fragile fabric of their love affair, and the dreams they worked so hard to maintain in each other threaten to rip them apart.", 8, 396, "/ylXCdC106IKiarftHkcacasaAcb.jpg", "/nadTlnTE6DdgmYsN4iWc2a2wiaI.jpg"));


    }

}

和适配器

public class MovieRecyclerViewAdapter extends RecyclerView.Adapter<MovieRecyclerViewAdapter.viewholder> {

     Context context;
     List<Movie> movies;
public MovieRecyclerViewAdapter (Context context,List<Movie>movies){
    this.context=context;
    this.movies=movies;
    }


    private Context getContext(){
    return context;
    }
    @Override
    public viewholder onCreateViewHolder( ViewGroup parent, int i) {

        View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_movie,parent,false);
        return new viewholder(v);
    }

    @Override
    public void onBindViewHolder( viewholder holder, int pos) {

Movie movie=movies.get(pos);
holder.tvTitle.setText(movie.getTitle());
holder.tvoverview.setText(movie.getOverview());
        Picasso.with(getContext()).load(movie.getPosterPath()).into(holder.ivmovieimage);
        //Glide.with(getContext()).load(movie.getPosterPath()).into(holder.ivmovieimage);
    }

    @Override
    public int getItemCount() {
        return movies.size();
    }
    public class viewholder extends RecyclerView.ViewHolder{
TextView tvTitle;
TextView tvoverview;
ImageView ivmovieimage;
        public viewholder( View view) {
            super(view);
            tvTitle=view.findViewById(R.id.tvTitle);
            tvoverview=view.findViewById(R.id.tvOverView);
            ivmovieimage=view.findViewById(R.id.ivMovieImage);
        }
    }
}

然后创建一个模型来保存这里的所有数据

package com.example.moviemanager.models;

public class Movie {
    String id;
    String title;
    String overview;
    float voteAverage;
    float voteCount;
    String posterPath;
    String backdropPath;
    public Movie(String id, String title, String overview, float voteAverage, float voteCount, String posterPath, String backdropPath) {
        this.id = id;
        this.title = title;
        this.overview = overview;
        this.voteAverage = voteAverage;
        this.voteCount = voteCount;
        this.posterPath = posterPath;
        this.backdropPath = backdropPath;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getOverview() {
        return overview;
    }

    public void setOverview(String overview) {
        this.overview = overview;
    }

    public float getVoteAverage() {
        return voteAverage;
    }

    public void setVoteAverage(float voteAverage) {
        this.voteAverage = voteAverage;
    }

    public float getVoteCount() {
        return voteCount;
    }

    public void setVoteCount(float voteCount) {
        this.voteCount = voteCount;
    }

    public String getPosterPath() {
        return  String.format( "https://image.tmdb.org/t/p/w342",posterPath);
    }

    public void setPosterPath(String posterPath) {
        this.posterPath =posterPath;
    }

    public String getBackdropPath() {
        return backdropPath;
    }

    public void setBackdropPath(String backdropPath) {
        this.backdropPath = backdropPath;
    }

}

和项目电影xml文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tool="http://schemas.android.com/tools"
    android:id="@+id/cvMovie"
    android:clickable="true"
    android:layout_marginBottom="@dimen/activity_vertical_margin"
    android:foreground="?android:attr/selectableItemBackground">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/ivMovieImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@mipmap/ic_launcher"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            />

        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toEndOf="@+id/ivMovieImage"
            android:layout_toRightOf="@+id/ivMovieImage"
            android:layout_marginLeft="@dimen/activity_small_margin"
            android:layout_marginTop="@dimen/activity_small_margin"
            android:maxLength="20"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            tool:text="Captain America" />
        <TextView
            android:id="@+id/tvOverView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_small_margin"
            android:layout_marginTop="@dimen/activity_small_margin"
            android:layout_toEndOf="@+id/ivMovieImage"
            android:layout_toRightOf="@+id/ivMovieImage"
            android:layout_below="@+id/tvTitle"
            android:maxLength="200"
            android:text="Captain America OverView"

            />

    </RelativeLayout>

</android.support.v7.widget.CardView>

并为片段

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    tools:context=".fragment.NowPlayingFragment">
<android.support.v7.widget.RecyclerView
    android:id="@+id/rvMovies"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
</android.support.v7.widget.RecyclerView>
</FrameLayout>

并为content_main

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".activities.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <FrameLayout
        android:id="@+id/flContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

</RelativeLayout>

我使用互联网权限清楚这些关于整个应用程序

android
1个回答
0
投票

只需在您的网址%s中添加此内容即可

  String.format( "https://image.tmdb.org/t/p/w342%s",posterPath)

因为您没有定义要以何种方式格式化字符串

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.