android控件滑动
⑴ android中可以滑动的控件式什么
在使用ScrollView和ListView这样的控件的时候,默认在右手边上是有链裤一个滑动的控件的。在我们用手棚纳简指滑动的时候,显示出茄吵来这个控件会不那么舒服,影响用户体验度。这里就是来说明一下,怎么样不显示滑动控件。
⑵ 在android程序里面,怎么让一个控件动起来呢
启一个线程,调用setprogress()的时候用Thread.sleep控制时间,平滑移动的距离和速度需要你自己逻辑控制。
run()方盯友山法中设定一个while(flag)循环,flag=true,凯中初始化progressbar的最大值,然后progressbar.getprogress()获得当前进度,把这个值赋给一个int变量,再调用setprogress(int)方告饥法设置进度,然后int变量自加,Thread.sleep控制好时间,在按钮的setOnClickListener中启动线程。需要停止的进度加一个判断,将flag变为false就可以了。
⑶ 安卓初学:有大段多行文本要在控件中显示,如何让它能有滚动或滑动显示全部文本
1.先进入散山Graphical Layout的可视化界面,
在窗体上放上scrollView1,并拉到最右下角,使很数埋大区域,
再在它的内部放上其它控件如 textView1,如果已经存在的
控件,就是剪切粘贴到它的内部,在Outline子窗体内就会
看到textView1在scrollView1的下一层;冲毕中
2.再在scrollView1内,设好滚动条参数;
当把大段多行文本用程序送到textView1后,就可滑动看到
整个文本段。
⑷ android滑动拼图验证码控件
package com.yolanda.code.library.widget;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import com.yolanda.code.library.R;
import com.yolanda.code.library.view.DiyStyleTextView;
/**
* @author Created by Yolanda on 2018/10/31.
* @description 滑动拼图验证码
*/
public final class DragImageView extends FrameLayout implements SeekBar.OnSeekBarChangeListener {
private final int showTipsTime = 1500;
private final int animeTime = 333;
private final int flashTime = 800;
private ImageView ivCover;
州拿 private ImageView ivBlock;
private SeekBar sb;
private TextView tvTips2;
private DiyStyleTextView tvTips;
private View vFlash, flContent;
private Handler handler = new Handler();
物闷 private Bitmap cover, block, completeCover;
private boolean isNormal;
public DragImageView(Context context) {
super(context);
init();
}
public DragImageView(Context context, AttributeSet attrs) {
罩迹弯 super(context, attrs);
init();
}
public DragImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
View.inflate(getContext(), R.layout.drag_view, this);
flContent = findViewById(R.id.drag_fl_content);
ivCover = findViewById(R.id.drag_iv_cover);
ivBlock = findViewById(R.id.drag_iv_block);
tvTips = findViewById(R.id.drag_tv_tips);
tvTips2 = findViewById(R.id.drag_tv_tips2);
vFlash = findViewById(R.id.drag_v_flash);
tvTips.setColorRegex("拼图|成功|失败|正确|[\\d\\.%]+", 0xfff75151);
sb = findViewById(R.id.drag_sb);
sb.setMax(getContext().getResources().getDisplayMetrics().widthPixels);
sb.setOnSeekBarChangeListener(this);
reset();
}
/**
* 设置资源
*
* @param cover 拼图
* @param block 滑块
* @param completeCover 完成的拼图
* @param block_y 滑块Y值比例
*/
public void setUp(Bitmap cover, Bitmap block, Bitmap completeCover, float block_y) {
this.cover = cover;
this.block = block;
this.completeCover = completeCover;
ivCover.setImageBitmap(completeCover);
ivBlock.setImageBitmap(block);
setLocation(1f * cover.getWidth() / cover.getHeight(), 1f * block.getHeight() / cover.getHeight(), block_y);
}
/**
* 设置比例大小
*
* @param cover_wph 图片bili
* @param block_size 滑块大小占高比
* @param block_y 滑块位置占高比
*/
private void setLocation(final float cover_wph, final float block_size, final float block_y) {
post(new Runnable() {
@Override
public void run() {
final int w = flContent.getMeasuredWidth();
int h = (int) (w / cover_wph);
ViewGroup.LayoutParams l = flContent.getLayoutParams();
l.width = w;
l.height = h;
flContent.setLayoutParams(l);
ViewGroup.MarginLayoutParams l2 = (MarginLayoutParams) ivBlock.getLayoutParams();
l2.height = (int) (h * block_size);
l2.width = l2.height * block.getWidth() / block.getHeight();
l2.topMargin = (int) (h * block_y);
ivBlock.setLayoutParams(l2);
}
});
}
public void ok() {
ivCover.setImageBitmap(completeCover);
blockHideAnime();
int penset = (int) (99 - (timeUse > 1 ? timeUse - 1 : 0) / 0.1f);
if (penset < 1) penset = 1;
tvTips.setText(String.format("拼图成功: 耗时%.1f秒,打败了%d%%的用户!", timeUse, penset));
tipsShowAnime(true);
flashShowAnime();
sb.setEnabled(false);
}
public void fail() {
twinkleImage(ivBlock);
tvTips.setText("拼图失败: 请重新拖曳滑块到正确的位置!");
tipsShowAnime(true);
handler.postDelayed(resetRun, showTipsTime);
sb.setEnabled(false);
}
public void reset() {
final int position = sb.getProgress();
if (position != 0) {
ValueAnimator animator = ValueAnimator.ofFloat(1f, 0);
animator.setDuration(animeTime).start();
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float f = (Float) animation.getAnimatedValue();
sb.setProgress((int) (position * f));
}
});
}
tipsShowAnime(false);
tips2ShowAnime(true);
sb.setEnabled(true);
ivBlock.setVisibility(GONE);
vFlash.setVisibility(GONE);
ivCover.setImageBitmap(completeCover);
isNormal = true;
}
//===================seekbar监听===================
private long timeTemp;
private float timeUse;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int cw = ivCover.getMeasuredWidth();
int bw = ivBlock.getMeasuredWidth();
ViewGroup.MarginLayoutParams l = (MarginLayoutParams) ivBlock.getLayoutParams();
l.leftMargin = (cw - bw) * progress / seekBar.getMax();
ivBlock.setLayoutParams(l);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
ivBlock.setVisibility(VISIBLE);
ivCover.setImageBitmap(cover);
tips2ShowAnime(false);
timeTemp = System.currentTimeMillis();
isNormal = false;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
timeUse = (System.currentTimeMillis() - timeTemp) / 1000.f;
if (dragListenner != null)
dragListenner.onDrag(seekBar.getProgress() * 1f / seekBar.getMax());
}
//===================seekbar监听===================
//闪烁滑块
private void twinkleImage(final View view) {
ValueAnimator animator = ValueAnimator.ofFloat(0, 1.0F);
animator.setTarget(view);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(showTipsTime).start();
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float f = (Float) animation.getAnimatedValue();
int time = (int) (showTipsTime * f);
if (time < 125)
view.setVisibility(INVISIBLE);
else if (time < 250)
view.setVisibility(VISIBLE);
else if (time < 375)
view.setVisibility(INVISIBLE);
else
view.setVisibility(VISIBLE);
}
});
}
//提示文本显示隐藏
private void tipsShowAnime(boolean isShow) {
if ((tvTips.getVisibility() == VISIBLE) == isShow)
return;
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, isShow ? 1f : 0f,
Animation.RELATIVE_TO_SELF, isShow ? 0f : 1f);
translateAnimation.setDuration(animeTime);
//translateAnimation.setInterpolator(new LinearInterpolator());
tvTips.setAnimation(translateAnimation);
tvTips.setVisibility(isShow ? VISIBLE : GONE);
}
//提示文本显示隐藏
private void tips2ShowAnime(boolean isShow) {
if ((tvTips2.getVisibility() == VISIBLE) == isShow)
return;
AlphaAnimation translateAnimation = new AlphaAnimation(isShow ? 0 : 1, isShow ? 1 : 0);
translateAnimation.setDuration(animeTime);
//translateAnimation.setInterpolator(new LinearInterpolator());
tvTips2.setAnimation(translateAnimation);
tvTips2.setVisibility(isShow ? VISIBLE : GONE);
}
//成功完成拼图滑块消失
private void blockHideAnime() {
AlphaAnimation translateAnimation = new AlphaAnimation(1, 0);
translateAnimation.setDuration(animeTime);
//translateAnimation.setInterpolator(new LinearInterpolator());
ivBlock.setAnimation(translateAnimation);
ivBlock.setVisibility(GONE);
}
//失败震动动画
private void failAnime() {
}
//成功高亮动画
private void flashShowAnime() {
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 1f,
Animation.RELATIVE_TO_SELF, -1f,
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 0f);
translateAnimation.setDuration(flashTime);
//translateAnimation.setInterpolator(new LinearInterpolator());
vFlash.setAnimation(translateAnimation);
vFlash.setVisibility(VISIBLE);
translateAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
vFlash.setVisibility(GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
//失败延时重置控件
private Runnable resetRun = new Runnable() {
@Override
public void run() {
tipsShowAnime(false);
tips2ShowAnime(true);
sb.setEnabled(true);
final int position = sb.getProgress();
ValueAnimator animator = ValueAnimator.ofFloat(1f, 0);
animator.setDuration(animeTime).start();
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float f = (Float) animation.getAnimatedValue();
sb.setProgress((int) (position * f));
}
});
isNormal = true;
}
};
//监听
private DragListenner dragListenner;
public interface DragListenner {
void onDrag(float position);
}
public void setDragListenner(DragListenner dragListenner) {
this.dragListenner = dragListenner;
}
}
⑸ Android怎么设置界面控件滑动,如图
viewpager+fragment+gridview就能实现。
你可以上这里下瞎局腔载源码,看看人腊凯家怎么写,也可磨衫以用第三方jar,几行代码就搞定这种效果。
https://github.com/LZLuzhuo/Case/tree/master/HomePageA
⑹ android像下图中的滑动效果的是什么控件做的
viewpager,下面是android滑动的效果图,
来自于android学习手册,android学习手册包含9个章节,108个例态陵州子,源码文档随便看,例子都是可交互,可运行, 源码采用帆蔽android studio目录结构,高亮显示代码,文档都采用文档结构图显示,可以快速定位。360手机助手中汪宽下载,图标上有贝壳
⑺ android 控件移动方法
Android控件位置都是自己设置的。
如果要控件放到任意位置,建议用RelativeLayout(相对布局)
然后给控件添加属性,把控件放到想要的位置
下面是相对布局中 控件能用到的属性。
属性值为true可false
android:layout_centerHrizontal 水平居中
android:layout_centerVertical 垂直居中
android:layout_centerInparent 相对于父元素完全居中
android:layout_alignParentBottom 贴紧父元素的下边缘
android:layout_alignParentLeft 贴紧父元素的左边缘
android:layout_alignParentRight 贴紧父元素的右边缘
android:layout_alignParentTop 贴紧父元素的上边缘
属性值必须为id的引用名
android:layout_below 在某元素的下方
android:layout_above 在某元素的上方
android:layout_toLeftOf 在某元素的左边
android:layout_toRightOf 在某元素的右边
android:layout_alignTop 本元素的上边缘和某元素的上边缘对齐
android:layout_alignLeft 本元素的左边缘和某元素的左边缘对齐
android:layout_alignBottom 本元素的下边缘和某元素下边缘对齐
android:layout_alignRight 本元素的右边缘和某元素右边缘对齐
属性值为具体的像素值班,如30dp
android:layout_marginBottom 离某元素底边缘的距离
android:layout_marginLeft 离某元素左边缘的的距离
android:layout_marginRight 离某元素的右边缘的距离
android:layout_marginTop 离某元素上边缘的距离
⑻ Android Seekbar控件,调用setMax后,seekbar滑动块无法滑动
你宏卖第一处的参数是不是应蔽袜逗该是: (int) ( ( endValue - startValue ) / stepValue)
要不然(endValue - startValue / stepValue) 是什么意思呢好正?
⑼ Android中WebView和父控件滑动冲突
问题场景 在项目的App中有一个ViewPager,它内部包含了WebView,而内部的webview加载了一个可以左右滑动的网页。当我们在网页滑动的时候,会直接切换到下一个WebView的页面,而不是优先响应WebView的滑动,这样一来WebView和ViewPager的滑动就出现了冲突。
但是产品期望场景是当手指落到WebView的可滑动区域是相应WebView的滑动事件,当滑动到边缘之后再相应ViewPager的滑动事件。
有了以上思路我们就能着手实现了,但是我们怎么能检测到WebView的滑动事件完成了呢?原来WebView的实现者也考虑到了这方面的需求,它暴露了一个方法
官方文档描述如下图:
通过上述方法我能就能监测到WebView滑动到了边界,接下来就是对拦截事件的处理了:
通过上述处理就能完美解决开篇的问题。