# Android Joystick Demo
_This is just a very simple demo which implement this [virtual joystick android Library](https://github.com/controlwear/virtual-joystick-android)._
![Alt text](/android-joystick-demo.png?raw=true "Double Android Joystick")
## Code
For those who don't want to browse the project or files, here it is...
#### Gradle file
Add library to dependencies.
```
dependencies {
...
compile 'io.github.controlwear:virtualjoystick:1.9.2'
}
```
#### Manifest
Force activity to landscape.
```xml
<activity
android:name=".MainActivity"
android:screenOrientation="landscape">
...
```
#### Layout
Just a couple of TextView and JoystickView to activity_main.xml
```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"
tools:context="io.github.controlwear.joystickdemo.MainActivity"
android:padding="16dp">
<TextView
android:id="@+id/textView_angle_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0°"/>
<TextView
android:id="@+id/textView_strength_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView_angle_left"
android:text="0%"/>
<io.github.controlwear.virtual.joystick.android.JoystickView
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/joystickView_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="32dp"
android:background="@drawable/joystick_background"
custom:JV_buttonImage="@drawable/pink_ball"
custom:JV_fixedCenter="false"/>
<TextView
android:id="@+id/textView_angle_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="0°"/>
<TextView
android:id="@+id/textView_strength_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView_angle_right"
android:text="0%"/>
<TextView
android:id="@+id/textView_coordinate_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView_strength_right"
android:text="x050:x050"/>
<io.github.controlwear.virtual.joystick.android.JoystickView
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/joystickView_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginTop="64dp"
custom:JV_borderWidth="8dp"
custom:JV_backgroundColor="#009688"
custom:JV_borderColor="#00796B"
custom:JV_buttonColor="#FF6E40"/>
</RelativeLayout>
```
#### Java
MainActivity.java
```java
public class MainActivity extends AppCompatActivity {
private TextView mTextViewAngleLeft;
private TextView mTextViewStrengthLeft;
private TextView mTextViewAngleRight;
private TextView mTextViewStrengthRight;
private TextView mTextViewCoordinateRight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextViewAngleLeft = (TextView) findViewById(R.id.textView_angle_left);
mTextViewStrengthLeft = (TextView) findViewById(R.id.textView_strength_left);
JoystickView joystickLeft = (JoystickView) findViewById(R.id.joystickView_left);
joystickLeft.setOnMoveListener(new JoystickView.OnMoveListener() {
@Override
public void onMove(int angle, int strength) {
mTextViewAngleLeft.setText(angle + "°");
mTextViewStrengthLeft.setText(strength + "%");
}
});
mTextViewAngleRight = (TextView) findViewById(R.id.textView_angle_right);
mTextViewStrengthRight = (TextView) findViewById(R.id.textView_strength_right);
mTextViewCoordinateRight = findViewById(R.id.textView_coordinate_right);
final JoystickView joystickRight = (JoystickView) findViewById(R.id.joystickView_right);
joystickRight.setOnMoveListener(new JoystickView.OnMoveListener() {
@SuppressLint("DefaultLocale")
@Override
public void onMove(int angle, int strength) {
mTextViewAngleRight.setText(angle + "°");
mTextViewStrengthRight.setText(strength + "%");
mTextViewCoordinateRight.setText(
String.format("x%03d:y%03d",
joystickRight.getNormalizedX(),
joystickRight.getNormalizedY())
);
}
});
}
}
```
#### Images
Here are the two images to put in drawable.
![Alt text](/app/src/main/res/drawable/pink_ball.png?raw=true "Android Joystick Button")
![Alt text](/app/src/main/res/drawable/joystick_background.png?raw=true "Android Joystick Background")
### And that's it.
The (quick) documentation of the library is [here](https://github.com/controlwear/virtual-joystick-android).
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
【AndroidStudio】安卓虚拟摇杆组件demo (572个子文件)
0V9ZiSLjSVVOUhRp0GdBy8tuddk= 172KB
0V9ZiSLjSVVOUhRp0GdBy8tuddk= 172KB
22d4fdfb996cd1dfa47d86b2c54180689c5152 220B
53G6pc3cnZj2IcUDm2zWytt6WtY= 21KB
53G6pc3cnZj2IcUDm2zWytt6WtY= 21KB
73lZxLiiaHlIKx4X+5lniHFd_Ac= 34KB
73lZxLiiaHlIKx4X+5lniHFd_Ac= 34KB
_v1T7U4x6uARJjkbQboGcaZtOw8= 667KB
_v1T7U4x6uARJjkbQboGcaZtOw8= 667KB
androidResources 23KB
resources-debug.ap_ 605KB
app-debug.apk 1.58MB
aRfkjEbOCBT7IYaoxE74rDdG+wA= 31KB
aRfkjEbOCBT7IYaoxE74rDdG+wA= 31KB
b466bc26a02bb74585efd89e62158cdf81480a 470B
B63EcpUC1bvCp6AmNu7lU1pMTwk= 9KB
B63EcpUC1bvCp6AmNu7lU1pMTwk= 9KB
gradlew.bat 2KB
executionHistory.bin 840KB
classAnalysis.bin 127KB
outputFiles.bin 56KB
jarAnalysis.bin 53KB
fileHashes.bin 40KB
taskHistory.bin 26KB
sha1-checksums.bin 23KB
md5-checksums.bin 19KB
resourceHashesCache.bin 18KB
last-build.bin 1B
MainActivity.class 2KB
MainActivity$2.class 2KB
MainActivity$1.class 1KB
BuildConfig.class 728B
config 312B
ctA5xYBs2cLb1O5WHOKRJf3P6fs= 33KB
ctA5xYBs2cLb1O5WHOKRJf3P6fs= 33KB
description 73B
classes.dex 2.12MB
classes.dex 1.98MB
MainActivity$2.dex 2KB
MainActivity.dex 2KB
MainActivity$1.dex 2KB
BuildConfig.dex 1016B
exclude 240B
FC3uPL4g3C28sszQaMgfBti6j9o= 11KB
FC3uPL4g3C28sszQaMgfBti6j9o= 11KB
values_values.arsc.flat 228KB
drawable_joystick_background.png.flat 142KB
values-v21_values-v21.arsc.flat 20KB
drawable_pink_ball.png.flat 19KB
mipmap-xxxhdpi_ic_launcher_round.png.flat 15KB
values-en-rXC_values-en-rXC.arsc.flat 11KB
mipmap-xxxhdpi_ic_launcher.png.flat 10KB
mipmap-xxhdpi_ic_launcher_round.png.flat 10KB
mipmap-xxhdpi_ic_launcher.png.flat 8KB
mipmap-xhdpi_ic_launcher_round.png.flat 6KB
mipmap-xhdpi_ic_launcher.png.flat 5KB
layout_activity_main.xml.flat 4KB
mipmap-hdpi_ic_launcher_round.png.flat 4KB
values-v17_values-v17.arsc.flat 4KB
mipmap-hdpi_ic_launcher.png.flat 3KB
values-v23_values-v23.arsc.flat 3KB
values-ne_values-ne.arsc.flat 3KB
values-my_values-my.arsc.flat 3KB
values-ml_values-ml.arsc.flat 3KB
values-ta_values-ta.arsc.flat 3KB
values-or_values-or.arsc.flat 3KB
values-kn_values-kn.arsc.flat 3KB
values-te_values-te.arsc.flat 3KB
values-bn_values-bn.arsc.flat 3KB
values-as_values-as.arsc.flat 3KB
values-si_values-si.arsc.flat 3KB
mipmap-mdpi_ic_launcher_round.png.flat 3KB
values-ka_values-ka.arsc.flat 3KB
values-km_values-km.arsc.flat 3KB
values-el_values-el.arsc.flat 3KB
values-mr_values-mr.arsc.flat 3KB
values-lo_values-lo.arsc.flat 3KB
values-hi_values-hi.arsc.flat 3KB
values-gu_values-gu.arsc.flat 3KB
values-bg_values-bg.arsc.flat 3KB
values-sr_values-sr.arsc.flat 3KB
values-be_values-be.arsc.flat 3KB
values-pa_values-pa.arsc.flat 3KB
values-lv_values-lv.arsc.flat 3KB
values-ur_values-ur.arsc.flat 3KB
values-ru_values-ru.arsc.flat 3KB
values-uk_values-uk.arsc.flat 2KB
values-mk_values-mk.arsc.flat 2KB
values-ky_values-ky.arsc.flat 2KB
values-hy_values-hy.arsc.flat 2KB
values-b+sr+Latn_values-b+sr+Latn.arsc.flat 2KB
values-th_values-th.arsc.flat 2KB
values-mn_values-mn.arsc.flat 2KB
values-fa_values-fa.arsc.flat 2KB
values-kk_values-kk.arsc.flat 2KB
values-fr-rCA_values-fr-rCA.arsc.flat 2KB
values-pt-rPT_values-pt-rPT.arsc.flat 2KB
values-am_values-am.arsc.flat 2KB
values-pt-rBR_values-pt-rBR.arsc.flat 2KB
values-lt_values-lt.arsc.flat 2KB
共 572 条
- 1
- 2
- 3
- 4
- 5
- 6
xanadw
- 粉丝: 1w+
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0