可以使用以下方法将RecyclerView捕捉到其中心:
LinearSnapHelper().attachToRecyclerView(recyclerView)
Run Code Online (Sandbox Code Playgroud)
例:
MainActivity.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val inflater = LayoutInflater.from(this)
recyclerView.adapter = object : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val textView = holder.itemView as TextView
textView.setBackgroundColor(if (position % 2 == 0) 0xffff0000.toInt() else 0xff00ff00.toInt())
textView.text = position.toString()
}
override fun getItemCount(): Int {
return 100
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
val view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false) as TextView
val cellSize = …Run Code Online (Sandbox Code Playgroud) 我要做的是在页面上制作一个不可见坐标的网格.然后我希望<div>在触发onclick时将其放置在最接近指针的任何网格坐标处.这是一个粗略的想法:
alt text http://i43.tinypic.com/x2uq84.jpg
我有跟踪鼠标坐标和<div>处理好的罚款.我坚持的是如何处理坐标网格的问题.
首先,我应该将所有坐标放在一个数组中,然后将我的onclick坐标与之比较?
或者看到我的网格坐标遵循规则,我可以做一些事情,比如找出哪个坐标是我的间距最接近onclick坐标的倍数?
然后,我从哪里开始计算哪个网格点坐标最接近?最好的方法是什么?
谢谢!
我正在实现一个水平RecyclerView按钮,在滚动后将项目捕捉到中心,就像谷歌播放App水平列表一样.这是一篇评论.
我的代码如下:
MainMenuAdapter mainMenuAdapter = new MainMenuAdapter(this, mDataset);
final LinearLayoutManager layoutManagaer = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView mainMenu = (RecyclerView) findViewById(R.id.main_menu);
mainMenu.setLayoutManager(layoutManagaer);
mainMenu.setAdapter(mainMenuAdapter);
final SnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(mainMenu);
Run Code Online (Sandbox Code Playgroud)
如何将中心项目(位置)RecyclerView折叠到中心后如何获得?对此没有任何监听器实现吗?此外,当触摸项目视图时,我想将其捕捉到中心.我怎样才能做到这一点?
我正在lazyRow 的帮助下制作日历。我现在遇到的问题是,我希望该行在一定的滚动量之后捕捉到索引,因此它不应该卡在索引之间。有没有办法做到这一点?
LazyRow(state = calendarViewModel.listState, modifier = Modifier.fillMaxWidth()) {
calendarYears.forEach {
items(it.months.count()) { index ->
calendarViewModel.onEvent(CalendarEvent.ClickedMenuItem(index))
CalendarRowItem(
modifier = Modifier.fillParentMaxWidth(),
calendarSize = it.months[index].amountOfDays,
initWeekday = it.months[index].startDayOfMonth.ordinal,
textColor = MaterialTheme.colors.secondaryVariant,
clickedColor = MaterialTheme.colors.primary,
textStyle = MaterialTheme.typography.body1
)
}
}
}
Run Code Online (Sandbox Code Playgroud) 有一个排序列表和一些随机值,我想找到值的范围.
列表是这样的:[0,5,10,15,20]并且值是,比方说8.
标准方法是从开始直到我们达到比我们更大的值(如下例所示),或执行二进制搜索.
grid = [0, 5, 10, 15, 20]
value = 8
result_index = 0
while result_index < len(grid) and grid[result_index] < value:
result_index += 1
print result_index
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更多的pythonic方法,因为这虽然很短,看起来有点眼睛疼痛.感谢您的时间!
这是我的覆盖代码 - 它只是计算捕捉到的位置:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
if(targetContentOffset->y < 400) {
targetContentOffset->y = 0;
return;
}
int baseCheck = 400;
while(baseCheck <= 10000) {
if(targetContentOffset->y > baseCheck && targetContentOffset->y < baseCheck + 800) {
targetContentOffset->y = (baseCheck + 340);
return;
}
baseCheck += 800;
}
targetContentOffset->y = 0;
}
Run Code Online (Sandbox Code Playgroud)
当我用手指按住一两秒钟来拖动滚动视图然后抬起我的手指时,它通常会动画到位.然而,当我快速"轻弹"它很少动画 - 它只是捕捉到targetContentOffset.我试图模拟默认的分页行为(尝试捕捉到自定义位置除外).
有任何想法吗?
我想在定义的网格单元格中将栅格从高分辨率重新采样到低分辨率(具有不同的范围).有没有办法使用现有的栅格文件作为捕捉的输入?
在光栅包,aggregate并且resample似乎是足够的,但我无法找到如何做到这一点.
我试图使用path元素渲染两个svg行.第一行宽度为1px,锐利,第二行宽度为2px,模糊,
两者的行程宽度相同.如何解决这个问题
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<path style="stroke-width:1;stroke:red;opacity:1;" d="M 300.5 250 L 300.5 300 "></path>
<path style=" stroke-width:1;stroke:red;opacity:1;" d="M 350 250 L 350 300 "></path>
</svg>
Run Code Online (Sandbox Code Playgroud) 我有一个折叠工具栏布局,下面是一个标签布局,下面是相应的viewpager.我想实现捕捉,这样当我折叠折叠工具栏布局超过一半并离开它时,它应该完全捕捉和折叠.我该怎么做?这是我的实际布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#231f20"
android:fitsSystemWindows="true">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="#231f20"
app:layout_anchor="@+id/appbar"
app:layout_anchorGravity="bottom"
app:tabGravity="fill"
app:tabMode="fixed" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="#FAC80A"
app:expandedTitleMarginBottom="110dp"
app:expandedTitleMarginStart="200dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax">
<ImageView
android:id="@+id/imageView78"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:background="@drawable/user_profile_bg_img"
android:scaleType="fitXY"
android:src="@drawable/gradient" />
<ImageView
android:id="@+id/imageView82"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="10dp"
android:src="@drawable/user_profile_shape_profile_pic"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp" />
<ImageView
android:id="@+id/imageView80"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:elevation="10dp"
android:layout_marginRight="60dp" …Run Code Online (Sandbox Code Playgroud) android snapping android-layout android-coordinatorlayout android-collapsingtoolbarlayout
我目前正在开发一个 SwiftUI 项目,我需要创建一个自定义垂直 ScrollView。要求是当用户停止滚动时,此 ScrollView 中的单元格捕捉到视图的中心。我知道 SwiftUI 的 ScrollView 通过修饰符提供了一定程度的自定义.scrollTargetBehavior(_:),但我发现的文档和示例并没有完全涵盖这种特定情况。
我尝试使用基本的scrollTargetBehavior .viewAligned,但捕捉行为不包括我正在寻找的捕捉效果。我知道 UIKit 通过 UICollectionView 和自定义布局属性提供了对滚动行为更精细的控制,但我的目标是纯粹在 SwiftUI 中实现这一点。
任何帮助将不胜感激。
干杯!
我有一个应用程序,对于快照视图真的没有意义,因为内容通常代表A4页面的信息和数据收集.
有没有办法禁用应用程序的捕捉视图,或者是在捕捉模式下显示应用程序图标的推荐方法?
我正在尝试重现 Mac 版最后一个 Tweetbot 的窗口捕捉/合并功能。如果您有 2 个窗口,并且将其中一个靠近另一个,它们就会对齐并合并到一个窗口中。
你知道我该怎么做吗?
谢谢
snapping ×12
android ×3
grid ×2
list ×2
aggregate ×1
android-collapsingtoolbarlayout ×1
animation ×1
cocoa ×1
custompaging ×1
javascript ×1
jquery ×1
nswindow ×1
paging ×1
pixel ×1
python ×1
r ×1
range ×1
raster ×1
resampling ×1
scrollview ×1
svg ×1
swift ×1
swiftui ×1
uiscrollview ×1
windows-8 ×1
winjs ×1