小编sky*_*rew的帖子

RecyclerView中的Android中心项目

我是android的新手.我不知道为什么我不能将我的项目放在RecyclerView中.

我想要的是如下图: -

实际

android渲染的内容如下图所示: -

现实

有没有办法将RecyclerView中的项目推向中心?所以看起来像这样: -

我想要这样

我还提供如下布局文件: -

recycler_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:id="@+id/calendar_itemContainer">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="April"
        android:id="@+id/calendar_txtMonth"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textColor="#ff58636d"
        android:textSize="16sp"
        android:gravity="center|center_vertical|center_horizontal"
        android:paddingTop="8dp"
        android:paddingLeft="12dp"
        android:paddingRight="12dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="21"
        android:id="@+id/calendar_txtDay"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/calendar_txtMonth"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textColor="#ff58636d"
        android:textSize="40sp"
        android:layout_marginTop="-10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingBottom="5dp"
        android:gravity="center|center_vertical|center_horizontal" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

fragment_calendar.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/calendar_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal"
        android:background="#ff2c3e50" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

和java代码: -

CalendarAdapter mAdapter = new CalendarAdapter(mDataset);
mLayoutManager = …
Run Code Online (Sandbox Code Playgroud)

java android android-recyclerview

27
推荐指数
4
解决办法
3万
查看次数

如何在GridLayout的RecyclerView项目装饰中跳过第一行?

我正在为GridLayout使用这个ItemDecoration类 - > https://github.com/devunwired/recyclerview-playground/blob/master/app/src/main/java/com/example/android/recyclerplayground/GridDividerDecoration.java

但问题是,我在GridLayout中的第一行是一个图像,我将跨度设置为2.

您可以按照以下屏幕截图查看我的屏幕:

截图

如何跳过第一行,以便ItemDecoration没有在图像上绘制?

下面是我用来添加ItemDecoration的代码: -

mRecyclerView.setHasFixedSize(true);
mLayoutManager = new GridLayoutManager(getActivity(), 2);
mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
        return position == 0 ? 2 : 1;
    }
});
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter.setHighlightsCallbacks(this);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.addItemDecoration(new GridDividerDecoration(getActivity()));
Run Code Online (Sandbox Code Playgroud)

我还修改了GridDividerDecoration类中的drawHorizo​​ntal方法,只有当imageview为null但仍无法工作时才绘制:

public void drawHorizontal(Canvas c, RecyclerView parent) {

    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();

    for (int i = 0; i < childCount; i++) {
        final View child = …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

10
推荐指数
1
解决办法
5529
查看次数

UITableViewCell自动布局宽度不适用于UIBezierPath

使用UIBezierPath时,UITableViewCell中的自动布局约束存在问题.我的细胞不会全宽.您可以看到图像1和图像2之间的不同.图像2我没有添加圆角.

图片1 使用UIBezierPath

图2 没有UIBezierPath

以前,我在UiView中遇到了与UIBezierPath相同的问题(你可以看到前面的2个UIView为"0").我正在使用的解决方法是屏蔽viewDidLayoutSubviews中的圆角,如下面的代码: -

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    [self.view layoutIfNeeded];

    UIView *container =  (UIView *)[self.view viewWithTag:100101];
    [container setBackgroundColor:[UIColor colorWithHexString:@"ffffff"]];
    [self setMaskTo:container byRoundingCorners:UIRectCornerAllCorners];
}
Run Code Online (Sandbox Code Playgroud)

但现在我陷入了UITableViewCell,因为我无法在viewDidLayoutSubviews中添加舍入角.我的代码如下: -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"myData";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    MyWClass *w = [_wData objectAtIndex:indexPath.row];

    UIView *container = (UIView *) [cell viewWithTag:200001];
    [container setBackgroundColor:[UIColor colorWithHexString:w.bgColor]];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:container.layer.bounds
                                                   byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                         cornerRadii:CGSizeMake(10.0, …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios autolayout

6
推荐指数
1
解决办法
947
查看次数

检索喜欢相同粉丝页面的用户的朋友

我试图找到facebook api来检索喜欢同一粉丝页面的用户的朋友,但我不认为新图表api能够做到这一点.

在stackoverflow中搜索时,我推出了这个FQL:

select user_id from like where object_id = "[page_id]" and user_id in (select uid2 from friend where uid1 = me())
Run Code Online (Sandbox Code Playgroud)

但是facebook回复了我

array(0) {
}
Run Code Online (Sandbox Code Playgroud)

有什么办法吗?

facebook facebook-fql facebook-graph-api

3
推荐指数
1
解决办法
1831
查看次数

带有两个切边的矩形

有2个切边的矩形

我不确定这个形状的具体名称是什么,但我可以称之为"半平行四边形"吗?我想纯粹使用CSS/CSS3制作这个形状.有帮助吗?还是教程?

css css3 css-shapes

3
推荐指数
1
解决办法
1816
查看次数