小编Van*_*ore的帖子

Android XML:阴影切断

我有一个带有边距的相对布局和一个嵌套在此布局中的浮动操作按钮.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/activityMargin"
            android:orientation="vertical"
            android:clipToPadding="false">


<android.support.design.widget.FloatingActionButton
    android:id="@+id/id_FABSave"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    app:srcCompat="@drawable/ic_save_white"/>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

正如您在附图中看到的那样,浮动动作按钮的阴影被切掉了.这是如何发生的,如何解决?

阴影的底部和右侧切断

xml android dropshadow

13
推荐指数
2
解决办法
3692
查看次数

Objective-C:通过UIDocumentInteractionController分享文本和图像到Instagram/Facebook/Twitter

我只是想知道是否有办法与UIDocumentInteractionController共享图片和文本.

我开发了一个具有共享功能的应用程序,到目前为止,我可以分享图片到Facebook,Twitter和Instagram,但没有图片的文字.

我现在用的是UIDocumentInteractionController,否则我不能设法通过Instagram的分享图片(例如,它是不可能的ActivityViewController这样做).

share facebook objective-c uidocumentinteraction instagram

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

在objective-c中设置自定义字体

嗨,

我正在尝试为我的标签设置一个字体,但是当我运行应用程序时它不会出现在我的iOS模拟器中.

_textLabel1 = [[UILabel alloc] initWithFrame:CGRectMake((CGFloat) (self.view.center.x - (self.view.bounds.size.width / textWidth / 2)),
            (CGFloat) (self.view.center.y * textPositionY), (CGFloat) (self.view.bounds.size.width / textWidth), (CGFloat) textHeight)];
_textLabel1.numberOfLines = 0;
_textLabel1.textAlignment = NSTextAlignmentCenter;
_textLabel1.textColor = clr;
_textLabel1.text = @"Favoriten";
[_textLabel1 setFont:[UIFont fontWithName:@"assets/fonts/Kingthings_Trypewriter_2.ttf" size:36]];
[_favouriteViewer addSubview:_textLabel1];
_textLabel1.font=[_textLabel1.font fontWithSize:25];
Run Code Online (Sandbox Code Playgroud)

我还在plist中添加了自定义字体:

<key>UIAppFonts</key>
<array>
    <string>Kingthings_Trypewriter_2.ttf</string>
</array>
Run Code Online (Sandbox Code Playgroud)

我将自定义字体保存在我调用的命名资产文件夹中:

[_textLabel1 setFont:[UIFont fontWithName:@"assets/fonts/Kingthings_Trypewriter_2.ttf" size:36]];
Run Code Online (Sandbox Code Playgroud)

我没有在模拟器中显示字体.

谢谢您的帮助!

编辑:我使用的是AppCode,而不是Xcode.

EDIT2:

感谢Ganesh Somani,我使用他的代码试图找出我的字体是否通过Copy Bundle资源正确添加到项目中,但不幸的是它仍未显示在日志中.

for(NSString *fontfamilyname in [UIFont familyNames])
{
    NSLog(@"Family:'%@'",fontfamilyname);
    for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
{
    NSLog(@"\tfont:'%@'",fontName);
}
NSLog(@"---");
}
Run Code Online (Sandbox Code Playgroud)

解决方案:出于某种原因,我的项目中有两个.plist文件.我输入以下代码,现在它可以工作:

<key>UIAppFonts</key> …
Run Code Online (Sandbox Code Playgroud)

fonts simulator objective-c custom-font

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

以编程方式设置CardView高程

我不知道这种方法是否最好,但我有以下问题:

我希望RecyclerView中的列表项(CardView)在单击按钮时进行动画处理,以便此按钮,此项目中的其他视图以及CardView的背景发生变化.

我从自定义的RecyclerView.ItemAnimator捕获animateChange :(到现在为止,动画只是通过animateLayoutChanges在xml中定义的淡入淡出)

public boolean animateChange(@NonNull RecyclerView.ViewHolder oldHolder, @NonNull RecyclerView.ViewHolder newHolder, @NonNull ItemHolderInfo preLayoutInfo, @NonNull ItemHolderInfo postLayoutInfo) {
    Log.d("Animation", "Test");
    final MyAdapter.MyViewHolder viewHolder = (MyAdapter.MyViewHolder) newHolder;

    viewHolder.mButtons.setVisibility(View.GONE);
    viewHolder.mHints.setVisibility(View.GONE);
    viewHolder.mImageView.setVisibility(View.GONE);

    ViewGroup.LayoutParams layoutParams = viewHolder.containerCardView.getLayoutParams();
    layoutParams.height = 192;
    viewHolder.containerCardView.setLayoutParams(layoutParams);
    viewHolder.containerCardView.setBackgroundResource(R.drawable.some_background);
    viewHolder.containerCardView.setElevation(20f);

    return true;
}
Run Code Online (Sandbox Code Playgroud)

如您所见,我在animateChange中手动设置背景.除了CardView的高程外,一切正常(或者至少可以说是按照预期).我试图手动设置高程,但没有显示高程.

编辑______

我的CardView里面有一个ImageView和一个按钮.按下按钮时,按钮本身和图片应淡出,并且cardView右侧应有一条红线.我试图通过将背景(使用setBackgroundResource)设置为:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:shape="rectangle">
        <gradient
            android:angle="180"
            android:centerColor="@android:color/transparent"
            android:centerX="0.1"
            android:startColor="@android:color/holo_red_dark"/>
        <corners
            android:bottomLeftRadius="2dip"
            android:bottomRightRadius="2dip"
            android:topLeftRadius="2dip"
            android:topRightRadius="2dip"/>
    </shape>
</item>

<item android:right="4dp">
    <shape android:shape="rectangle">
        <solid android:color="@android:color/white" />
    </shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

这只是一个xml drawable,右边是红线.对于达到目标的其他方式,您有什么建议吗?

android elevation android-recyclerview cardview

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

分页库:跳转列表项+最后总是相同的数据

我正在尝试使用 Paging 库、MVVM 和 LiveData 实现一个无限列表。

在我的视图(在我的例子中是我的片段)中,我从 ViewModel 中请求数据并观察变化:

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        viewModel.getItems("someSearchQuery")
        viewModel.pagedItems.observe(this, Observer<PagedList<Item>> {
            // ItemPagedRecyclerAdapter
            // EDIT --> Found this in the official Google example
            // Workaround for an issue where RecyclerView incorrectly uses the loading / spinner
            // item added to the end of the list as an anchor during initial load.
            val layoutManager = (recycler.layoutManager as LinearLayoutManager)
            val position = layoutManager.findFirstCompletelyVisibleItemPosition()
            if (position != RecyclerView.NO_POSITION) {
                recycler.scrollToPosition(position)
            }
        }) …
Run Code Online (Sandbox Code Playgroud)

android android-jetpack android-paging-library

0
推荐指数
1
解决办法
2322
查看次数