我成功地在CustomViewPager的开头创建了一个动画,它就像一个Carousel.所以在这里,我的物品来自左侧,并在3秒内向右移动.事情是它只是一个翻译我想知道是否可以让我的viewpager从远处滚动到他的最终位置.
你有没有办法做到这一点?问候.
编辑:所以我尝试了其他的东西,我创建了自定义ScrollToAnimation.我成功地创造了我想要的东西但运动不顺畅你能帮助我吗?我的新代码:
import android.support.v4.view.ViewPager;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import java.util.Calendar;
public class ScrollToAnimation extends Animation {
private int currentIndex = 0, nbChilds = -1, deltaT = 0;
private float fromX, toX;
private long animationStart;
private ViewPager viewpager;
public ScrollToAnimation(ViewPager viewpager, float fromX, float toX, int duration) {
this.viewpager = viewpager;
this.fromX = fromX;
this.toX = toX;
nbChilds = viewpager.getChildCount();
deltaT = duration / nbChilds;
setDuration(duration);
animationStart = Calendar.getInstance().getTimeInMillis();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t); …Run Code Online (Sandbox Code Playgroud) 我尝试测试一种简单的方法,该方法应该为iOS 10创建并传递通知。
func displayPlaceNotificationContent() {
let unMutableNotificationContent = generateNotification()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: getNotificationIdentifier(), content: unMutableNotificationContent, trigger: trigger)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request, withCompletionHandler: nil)
}
Run Code Online (Sandbox Code Playgroud)
这是此方法的单元测试:
func testDisplayNotification() {
notificationManager?.displayPlaceNotificationContent())
XCTAssertTrue((notificationManager.isNotificationDisplayed())
}
Run Code Online (Sandbox Code Playgroud)
当我尝试执行单元测试时,我有一个异常,即堆栈跟踪:
2017-09-12 13:52:25.931564+0200 xctest[17170:1252988] *** Assertion failure in -[UNUserNotificationCenter initWithBundleProxy:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UserNotifications_Sim/UserNotifications-156/UNUserNotificationCenter.m:50
2017-09-12 13:52:25.933629+0200 xctest[17170:1252988] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: bundleProxy != nil'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b0a9aeb __exceptionPreprocess …Run Code Online (Sandbox Code Playgroud) 我尝试做一个简单的摆动窗口,但布局并不容易......我的意思是我只想要一个带有 3 个面板的窗口:
但我无法成功地拥有我想要的东西。我使用了 gridLayout(3,1) 但无法指定高度。
public class Window extends JFrame implements Serializable {
private JPanel _header;
private JPanel _content;
private JPanel _footer;
public Window() {
GridLayout grid = new GridLayout(3,1);
setLayout(grid);
_header = new JPanel();
_header.setBackground(Color.GRAY);
getContentPane().add(_header);
_content = new JPanel();
JScrollPane jsp = new JScrollPane(_content, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
getContentPane().add(jsp);
_footer = new JPanel();
_footer.setBackground(Color.GRAY);
getContentPane().add(_footer);
pack();
validate();
setTitle("Chat client");
setVisible(true);
setSize(500, 500);
setLocationRelativeTo(null);
}
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗 ?此致
最近我创建了自己的云服务器,我需要能够从php表单上传文件,将文件从我的电脑传输到我自己的云服务器.所以我尝试使用Curl,像这样:
<?php
$url = "5.25.9.14/remote.php/webdav/plus.png";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); // -X PUT
curl_setopt($ch, CURLOPT_USERPWD, "root:root"); // --user
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'img/plus.png' => '@'.realpath('img/plus.png')
)
);
$output = curl_exec($ch);
curl_close($ch);
?>
Run Code Online (Sandbox Code Playgroud)
我受到了这篇文章和这个命令的启发:
curl -X PUT "http://server.com/owncloud/remote.php/webdav/file.zip" --data-binary @"/Users/Root/Downloads/file.zip"
Run Code Online (Sandbox Code Playgroud)
命令行,他正在工作,但不是我的PHP.我成功上传文件,但文件已损坏,我不知道原因:/.也许我错过了MIME类型?获取损坏的文件是否足够?
你看到我错了吗?最好的问候,Zed13
编辑:当我创建我上传文件的文件时,它是类型数据而不是png,奇怪......
我有一个自定义ViewPager,就像一个Carousel,我希望能够在一个上显示多个页面.为此,我们有两个解决方案:
第一个解决方案工作得很好,但我希望能够精确确定当前页面的百分比.问题在于getPageWidth解决方案,我的当前页面在左侧移动.这是合乎逻辑的,因为她只占她以前尺寸的80%.所以我试图覆盖我的自定义ViewPager的scrollTo函数,如下所示:
@Override
public void scrollTo(int x, int y) {
x = (int) (x - (getWidth() - getWidth()*getAdapter().getPageWidth(getCurrentItem()))/2);
super.scrollTo(x, y);
}
Run Code Online (Sandbox Code Playgroud)
它正在工作,但我不能像以前一样滚动,它只是表现得很奇怪,不要朝着好的方向前进,不要按照手指......有没有任何解决方案可以让我有一个工作滚动和居中当前页面 ?
这是我的适配器:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import java.util.ArrayList;
public class CarouselAdapter extends FragmentPagerAdapter implements ViewPager.OnPageChangeListener {
private ArrayList<Entity> mData = new ArrayList<>();
private ScaledRelativeLayout cur = null, next = null;
private float scale;
private MainActivity context;
private FragmentManager fragmentManager;
public CarouselAdapter(MainActivity context, FragmentManager fragmentManager, ArrayList<Entity> mData) {
super(fragmentManager);
this.fragmentManager = fragmentManager;
this.context …Run Code Online (Sandbox Code Playgroud)