SeekBar的使用(二):控制Button的缩放,移动及旋转
2014-04-16 22:03
459 查看
package com.example.androidtest; import android.os.Bundle; import android.app.Activity; import android.widget.Button; import android.widget.SeekBar; import android.util.Log; public class MainActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button rotatingButton = (Button)findViewById(R.id.rotatingButton); SeekBar seekBar; seekBar = (SeekBar)findViewById(R.id.translationX); seekBar.setMax(400); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub rotatingButton.setTranslationX((float)progress); } }); seekBar = (SeekBar)findViewById(R.id.translationY); seekBar.setMax(800); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub rotatingButton.setTranslationY((float)progress); } }); seekBar = (SeekBar)findViewById(R.id.scaleX); seekBar.setMax(50); seekBar.setProgress(10); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub rotatingButton.setScaleX((float)progress / 10f); } }); seekBar = (SeekBar)findViewById(R.id.scaleY); seekBar.setMax(50); seekBar.setProgress(10); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub rotatingButton.setScaleY((float)progress / 10f); } }); seekBar = (SeekBar)findViewById(R.id.rotationX); seekBar.setMax(360); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub rotatingButton.setRotationX((float)progress); } }); seekBar = (SeekBar)findViewById(R.id.rotationY); seekBar.setMax(360); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub rotatingButton.setRotationY((float)progress); } }); seekBar = (SeekBar)findViewById(R.id.rotationZ); seekBar.setMax(360); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub rotatingButton.setRotation((float)progress); } }); } }
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
android:splitMotionEvents="true"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:splitMotionEvents="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:textStyle="bold"
android:text="TX"
/>
<SeekBar
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/translationX"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dip"
android:paddingRight="5dip"
android:textStyle="bold"
android:text="TY"
/>
<SeekBar
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/translationY"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:splitMotionEvents="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:textStyle="bold"
android:text="SX"
/>
<SeekBar
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scaleX"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dip"
android:paddingRight="5dip"
android:textStyle="bold"
android:text="SY"
/>
<SeekBar
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scaleY"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:splitMotionEvents="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:textStyle="bold"
android:text="X"
/>
<SeekBar
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rotationX"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dip"
android:paddingRight="5dip"
android:textStyle="bold"
android:text="Y"
/>
<SeekBar
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rotationY"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dip"
android:paddingRight="5dip"
android:textStyle="bold"
android:text="Z"
/>
<SeekBar
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rotationZ"
/>
</LinearLayout>
<Button
android:layout_width="200dip"
android:layout_height="150dip"
android:layout_marginLeft="50dip"
android:layout_marginTop="50dip"
android:text="Rotating Button"
android:id="@+id/rotatingButton"
/>
</LinearLayout>
相关文章推荐
- 008-实现Unity3d中使用LeanTouch插件进行触屏控制(拖拽、移动、缩放旋转...)
- unity使用鼠标控制移动、缩放、旋转
- UIKit 图片的移动、位移、旋转、缩放、翻转、翻页等特效的使用
- OpenGL之鼠标控制坐标系旋转、缩放、移动
- Android中利用matrix 控制图片的旋转、缩放、移动
- Unity3D 控制物体移动、旋转、缩放
- AutoCAD .Net 使用 DrawJig 来动态地移动、旋转、缩放多个图元
- iOS开发的一些小技术:让UIImage有缩放功能、控制log的输出、xcode修改文件注释、随机数的使用、在UIImageView 中旋转图像、在Quartz中如何设置旋转点、创建.plist文件并存储
- Unity3d修炼之路:GUIbutton简单使用,完毕对一个简单对象Cube的移动,旋转
- 使用WPF Resource以及Transform等技术实现鼠标控制图片缩放和移动的效果
- web手势库AlloyFinger运用( 控制CANVAS中图片移动、缩放、旋转)
- IOS&Android通用屏幕控制(移动旋转缩放)
- 【IOS】使用手势对UIImageView进行缩放、旋转和移动
- Unity3D 控制物体移动、旋转、缩放
- 使用WPF Resource以及Transform等技术实现鼠标控制图片缩放和移动的效果
- 使用手势对UIImageView进行缩放、旋转和移动
- Android之matrix类控制图片的旋转、缩放、移动
- IOS&Android通用屏幕控制(移动旋转缩放)
- 手势检测实现相册的左右滑动(并加上移动与旋转的特效) 首先,activity_main.xml里,使用ViewFlipper组件(可使用动画控制多个组件之间的切换效果) <?xml version="
- Android matrix 控制图片的旋转、缩放、移动