如标题所示:我想知道如何获取AdapterView中所有当前显示项目的列表(数组).
为什么?我的AdapterView中显示的对象需要在用户关闭AdapterView后释放侦听器.我需要这样做才能优化我的应用.
或者是否有任何方法(我可以覆盖)在视图的破坏上执行?
我用a RecyclerView来水平显示项目.我想将所选项目设置为视图的中心,如下所示
这就是我这样做的方式:
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
Run Code Online (Sandbox Code Playgroud) 好!过去几周我一直试图这样做,似乎无法找到一个很好的解决方案来实现我想要的.一直在尝试使用HorizontalScrollView,Gallery(不推荐使用).
我现在正在研究RecycleView,因为我遇到了这个方法.smoothScrollToPosition(),并认为这可能对我有帮助.
以下是我想要完成的事情的说明:

我还必须能够以编程方式创建相对布局
任何人都可以向我指出如何实现这一目标吗?有没有本土的方法呢?
编辑:在进一步了解@CommonsWare关于调查ViewPager的建议和来自Dave Smith的commonsware.com/blog/2012/08/20/第三篇文章后,我认为这是要走的路.还没有将它改为我的使用,但看起来不错.
我正在使用他的Github中的Dave Smiths样本:https://gist.github.com/devunwired/8cbe094bb7a783e37ad1
android horizontalscrollview android-scrollview swipe-gesture android-relativelayout
我需要一个像这样的RecyclerView:
它应该做:
每次显示7件物品(DONE)
将RecyclerView置于中央可见项目(DONE)的中心
当我向右/向左滚动时,中央项目将"突出显示"(按钮被选中>蓝色)(需要帮助)
当我点击一个按钮时,它将以平滑的scrool为中心(需要帮助)
我使用SnapHelperclass将RecyclerView置于中心项目的中心(我检索中心可见项目,让最近的孩子到屏幕中心)
我的适配器:
public class RvTrendsGraphAdapter extends RecyclerView.Adapter<RvTrendsGraphAdapter.ViewHolder> {
private float deviceWidth;
private float itemWidth;
private List<RvTrendsGraphModel> models;
private Context context;
public RvTrendsGraphAdapter(Context context, List<RvTrendsGraphModel> models) {
this.models = models;
this.context = context;
}
private Context getContext() {
return context;
}
public class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.rv_trends_graph_layout) PercentRelativeLayout rootLayout;
@BindView(R.id.rv_trends_graph_layout_superiore) PercentRelativeLayout layoutSuperiore;
@BindView(R.id.rv_trends_graph_layout_inferiore) RelativeLayout layoutInferiore;
@BindView(R.id.rv_trends_graph_vertical_progressbar) ProgressBar verticalProgressBar;
@BindView(R.id.rv_trends_graph_button) Button timeLapseButton;
public ViewHolder(View itemView) …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的应用程序实现某种轮选择器,因为当前的选项依赖于自定义Views或旧的ListView,所以我想基于我的解决方案RecyclerView.
我所做的到现在为止是在开始和结束时设定RecyclerView 2 View与不同类型,命名PADDING_TYPE 以使第一和最后一个项目的垂直居中RecyclerView.
recyclerView.post(new Runnable() {
@Override
public void run() {
//80dp is the height of a regular list item
int paddingHeight = ((recyclerView.getHeight()-SettingsManager.dptopixels(80))/2);
binding.getRoot().getLayoutParams().height = paddingHeight;
}
});
Run Code Online (Sandbox Code Playgroud)
现在我试图了解如何使所选项目保持垂直居中.
到目前为止我尝试了什么:
1- LinearSnapHelper
LinearSnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(mRecyclerView);
Run Code Online (Sandbox Code Playgroud)
没有按预期工作,我也尝试覆盖几种方法(可能是以错误的方式),但我无法使其自动垂直居中选择.并且它不够活泼,所选项目"移动"而不是被锁定到垂直中心.
2-自定义 RecyclerView.OnScrollListener
我尝试通过更改 此行来调整此处提出的代码,即用于水平滚动RecyclerView.OnScrollListener
allPixelsDate += dx;
Run Code Online (Sandbox Code Playgroud)
与垂直滚动差异:
allPixelsDate += dy;
Run Code Online (Sandbox Code Playgroud)
此实现接近工作,因为它选择最接近列表垂直中心的项目,但不将其锁定到中心.
是否有可能实现这样的结果?怎么样?
更清楚一点:我想在1:10 得到这里显示的结果.选择被"锁定"在中心.
自动滚动存在问题,并且使用代码很难移动到某个特定位置.
我使用水平滚动和中心选择使两个recyclerView相互依赖.
所以我的问题是使用Notifydatasetchanged的方法并将recyclelerView postion重置为0并且它的滚动选择范围因为它返回了错误的索引...
当我想在更改数据后获得中心选择索引.我正在使用下面的示例通过一些编辑实现此目的.
我需要将第一个recyclelerView适配器滚动的数据更改为第二个使用数据更改的recyclerView适配器.
但是scrollview将位置设置在第一个位置我尝试了notifyItemRangeChanged(int,int)notifyItemRangeInserted(int,int)方法......
详细说明:我正在更改类型并重置Look scrollview的值.我需要更改底部scrollview的选定位置.特别是我不能通过改变数据来获得中心位置.意味着如果我通知适配器而不是索引将保持不变.重置数据后,我需要像普通适配器一样工作.
提前致谢.
public void getRecyclerview_Type() {
final RecyclerView recyclerView_Type = (RecyclerView) findViewById(R.id.recycleView);
if (recyclerView_Type != null) {
recyclerView_Type.postDelayed(new Runnable() {
@Override
public void run() {
setTypeValue();
}
}, 300);
recyclerView_Type.postDelayed(new Runnable() {
@Override
public void run() {
// recyclerView_Type.smoothScrollToPosition(Type_Adapter.getItemCount() - 1);
setTypeValue();
}
}, 5000);
}
ViewTreeObserver treeObserver = recyclerView_Type.getViewTreeObserver();
treeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
recyclerView_Type.getViewTreeObserver().removeOnPreDrawListener(this);
finalWidthDate = recyclerView_Type.getMeasuredWidth();
itemWidthDate = getResources().getDimension(R.dimen.item_dob_width_padding);
paddingDate = (finalWidthDate - itemWidthDate) / …Run Code Online (Sandbox Code Playgroud) android horizontalscrollview android-layout material-design android-recyclerview
我动态加载了一些(1000)图像HorizontalcsrollView.用户可以HorizontalScrollView正面和背面滚动.
我需要的是,在滚动时找到屏幕中心的项目位置.FYR,我HorizontalScrollView从屏幕中心开始,到中心结束.
我试过addOnScrollChangedListener了HorizontalScrollview,但我无法得到中心项目的确切位置.
编辑:尝试获取x位置和左侧位置,同时滚动,但始终返回0.
注意,我已经将padding左右设置为my HorizontalScrollView.
它始终从屏幕中心开始,到屏幕中心结束.
horizontalScrollView1.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
int x1 = horizontalScrollView1.getLeft();
int getX=(int)horizontalScrollView1.getX();
}
});
Run Code Online (Sandbox Code Playgroud)
布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:fillViewport="true"
android:scrollbars="none">
<RelativeLayout
android:id="@+id/layLandmarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:id="@+id/viewWhite"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_centerInParent="true"
android:background="@color/white" />
</RelativeLayout>
</HorizontalScrollView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
班级档案:
ImageView iv;
RelativeLayout …Run Code Online (Sandbox Code Playgroud) 我试图放大中心最listview项目.(最后,我希望将其扩展为一种简单而轻盈的3D效果,在屏幕中间放置元素时会放大,在下方放大时缩小,黑色背景和文本项目放大和缩小...)
所以,我做了一个虚拟列表视图,每一行都是一个textview元素.下面,我有一个自定义适配器.
我所做的唯一相关修改是:
在OnCreate(),我将以下变量传递给适配器:
int v = (listview.getLastVisiblePosition() - listview.getFirstVisiblePosition()) + 1;
Run Code Online (Sandbox Code Playgroud)
在Adapter的getView()中,我得到了这个:
if (position == x/2) {
textView.setHeight(100);
}
Run Code Online (Sandbox Code Playgroud)
无论如何这里是所有的代码,我已经跳过了进口:(它不是那么大!......大部分是相当普遍的)
MainActivity.java:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ListView listview = (ListView) findViewById(R.id.listview);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7","iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7","iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X" };
final ArrayList<String> list = new ArrayList<String>();
for (int i …Run Code Online (Sandbox Code Playgroud) 当我们滚动浏览器视图时,我正在尝试更改选项卡。
我已经在单个回收商视图中列出了这些项目。
因此,当我到达每个部分的标题(例如早餐然后早餐标签应该处于活动状态)时,如何相应地更改标签?
上面的 gif 解释了我的查询。请建议我一个解决方案。