1

我想在我的应用程序上显示一张带有图片的幻灯片,我实现了一个水平的 RecyclerView。

左侧的屏幕是右侧同一屏幕的运行时屏幕截图,显示在 Layout Inspector 中,在我将照片添加到 recyclerview 之后

手机上的SS SS上李

RecyclerView 的原始位置在 CardView 内,我将其移出,因为它也没有显示在那里。关于为什么的任何想法?

一些代码:

活动.xml

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TheActivity">

    <fragment
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="TheFragment"
        android:tag="@string/the_tag"
        tools:layout="@layout/the_layout"
        android:id="@+id/the_id"/>
</FrameLayout>

片段.xml

<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:bind="http://schemas.android.com/apk/res-auto"
    tools:context="TheActivity" >

<data>
    <!-- Some vars -->
</data>

<LinearLayout android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView  android:visibility="visible"
        android:id="@+id/frag_add_property_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:orientation="vertical"
            android:focusableInTouchMode="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">               
            <android.support.v7.widget.RecyclerView android:id="@+id/the_rv"
                android:layout_width="match_parent"
                android:layout_height="150dp"
     app:layoutManager="android.support.v7.widget.LinearLayoutManager"                    
                android:orientation="horizontal"
  android:layout_marginBottom="@dimen/activity_half_vertical_margin"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

public class TheFragment extends BaseFragment implements TheView { 

    private PictureFilesAdapter adapter;
    @BindView(R.id.rv_add_property_pics) 
    RecyclerView imageRv;

    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        bind = DataBindingUtil.inflate(inflater, getLayout(), container, false);
        unbinder = ButterKnife.bind(this, bind.getRoot());

        Drawable dividerDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.rv_item_hor_divider);
        imageRv.addItemDecoration(new CustomItemDecoration(dividerDrawable));

        return bind.getRoot();
    }

class PictureFilesAdapter extends RecyclerView.Adapter<PropertyPicturesViewHolder> {

    Context context;
    public ArrayList<File> files;
    public ArrayList<File> getFiles() {
        return files;
    }

    AddPropertyView view;

    PictureFilesAdapter(AddPropertyView view, Context context) {
        this.context = context;
        this.files = new ArrayList<>();
        this.view = view;
    }

    @Override
    public PropertyPicturesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.item_rv_add_property, parent, false);
        return new AddPropertyFragment.PropertyPicturesViewHolder(v);
    }

    @Override
    public void onBindViewHolder(PropertyPicturesViewHolder holder, int position) {
        holder.textView.setText(files.get(position).getAbsolutePath());

        Picasso.with(context)
                .load(files.get(position))
                .into(holder.imageView);
    }

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

    void addFile(File file) {
        this.files.add(file);
        notifyDataSetChanged();
    }

}

class PropertyPicturesViewHolder extends RecyclerView.ViewHolder {

    private Uri uri;
    @BindView(R.id.item_rv_add_prop_image) ImageView imageView;
    @BindView(R.id.item_rv_add_prop_image_src) TextView textView;

    PropertyPicturesViewHolder(View view) {
        super(view);

        ButterKnife.bind(this, view);
        view.setOnClickListener((v) -> {
            // some logic
        });
    }
}

}

4

2 回答 2

1

事实证明,即使对于毕加索来说,位图也太大了。在显示之前缩小位图确实很神奇。

于 2017-05-02T03:38:16.380 回答
-1

你能提供你的代码吗?

为什么它没有出现有多种可能性。

  1. 它没有布局管理器
  2. 它没有适配器
  3. 返回adapter.getCount()0
于 2017-05-02T01:12:00.710 回答