Code Monkey home page Code Monkey logo

Comments (9)

spysoos avatar spysoos commented on July 17, 2024

不知道怎么贴图
[http://ys-f.ys168.com/383712285/nxsSwvk2J76534U7L36/TIM%E6%88%AA%E5%9B%BE20171121092606.png]效果图

from viewpagerlayoutmanager.

leochuan avatar leochuan commented on July 17, 2024

@spysoos 方便的话,把你recyclerView所在的xml贴上来看看

from viewpagerlayoutmanager.

leochuan avatar leochuan commented on July 17, 2024

我自己试了下,在DialogFragment里给item宽度设置为match_parent,并没有出现你说的这种情况,最好可以给我看下你的布局文件,这样可以让我比较快速的定位问题

from viewpagerlayoutmanager.

spysoos avatar spysoos commented on July 17, 2024

不好意思,忘记start,好不容易找回这里。

以下是DialogFragment的布局:

`

<android.support.v7.widget.RecyclerView
    android:id="@+id/content_rv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none"
    android:overScrollMode="never"
    tools:listitem="@layout/item_text"/>

<LinearLayout
    android:id="@+id/option_panel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:visibility="visible">

    <Button
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_weight="1"
        android:background="@android:color/black"
        android:gravity="center"
        android:orientation="horizontal"
        android:text="取消"
        android:textColor="#ffffff"/>

    <Button
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_weight="1"
        android:background="@android:color/black"
        android:gravity="center"
        android:orientation="horizontal"
        android:text="确认"
        android:textColor="#ffffff"/>
</LinearLayout>

`

这是Item的布局:
`

<TextView
    android:id="@+id/content"
    android:textSize="15sp"
    android:gravity="center"
    android:textColor="#353535"
    android:lines="1"
    tools:text="2017"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

`

这是DialogFragment的源码:
`public class Dialog extends DialogFragment {

public static Dialog newInstance() {
    Bundle bundle = new Bundle();
    Dialog dialog = new Dialog();
    dialog.setArguments(bundle);
    return dialog;
}

@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.view_dialog_date, container);
    RecyclerView recyclerView = view.findViewById(R.id.content_rv);
    ScaleLayoutManager scaleLayoutManager = new ScaleLayoutManager(10);
    scaleLayoutManager.setOrientation(ViewPagerLayoutManager.VERTICAL);
    recyclerView.setAdapter(new DataAdapter2());
    recyclerView.setLayoutManager(scaleLayoutManager);

    return view;
}

}
适配器:public class DataAdapter2 extends RecyclerView.Adapter<DataAdapter2.ViewHolder> {
private String[] images = {"2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017"};

@Override
public DataAdapter2.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_text, parent, false));
}

@Override
public void onBindViewHolder(DataAdapter2.ViewHolder holder, int position) {
    holder.tvView.setText(images[position]);
    holder.tvView.setTag(position);
}

@Override
public int getItemCount() {
    return images.length;
}

class ViewHolder extends RecyclerView.ViewHolder {
    TextView tvView;

    ViewHolder(View itemView) {
        super(itemView);
        tvView = (TextView) itemView.findViewById(R.id.content);
        tvView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "clicked:" + v.getTag(), Toast.LENGTH_SHORT).show();
            }
        });
    }
}

}
`

tim 20171129171617

from viewpagerlayoutmanager.

spysoos avatar spysoos commented on July 17, 2024

如果可以 可以留下邮箱 我发工程给你

from viewpagerlayoutmanager.

leochuan avatar leochuan commented on July 17, 2024

@spysoos 这个问题可能我暂时解决不掉, LayoutManager 有一个 shouldMeasureTwice方法是package作用域的,我不能覆写他,这个方法的作用是在子view大小不确定的时候再次测量的。注释上说不能复写的原因是会在未来重构的时候移除他。而让ViewpagerLayoutManager继承LinearLayoutManager的话改动会比较大,所以我的建议是你设置一下DialogFragment的大小,然后给item的宽高设置一个固定的值。

from viewpagerlayoutmanager.

spysoos avatar spysoos commented on July 17, 2024

@leochuan 目前我也是设固定值解决的,其他都很OK,3Q

from viewpagerlayoutmanager.

leochuan avatar leochuan commented on July 17, 2024

@spysoos 我想了想,还是改成继承自LinearLayoutManager了。看效果上好像没什么问题,我看看没别的问题应该会更新一下

from viewpagerlayoutmanager.

leochuan avatar leochuan commented on July 17, 2024

Fix by commit: 153e0a6
好了,更新了,建议等新版上传好之后用新的版本,如果有用到无限滚动的话

from viewpagerlayoutmanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.