我正在创建一个Android应用程序,我要添加一个水平滚动按钮来增加/减少计数器。如何使用水平滚动按钮增加或减少计数器
例如,如果用户滚动向右按钮时,计数器应增加1并向左滚动将由1
降低柜台请告诉我,我应该怎么做才能完成任务。看看具有我想要的功能的附加图像。
我想计数器增加,只有当用户滚动特定的按钮,而不是当他挥笔别处屏幕
我正在创建一个Android应用程序,我要添加一个水平滚动按钮来增加/减少计数器。如何使用水平滚动按钮增加或减少计数器
例如,如果用户滚动向右按钮时,计数器应增加1并向左滚动将由1
降低柜台请告诉我,我应该怎么做才能完成任务。看看具有我想要的功能的附加图像。
我想计数器增加,只有当用户滚动特定的按钮,而不是当他挥笔别处屏幕
。您可以使用一个SeekBar
增加或减少的计数器。布局的一个简单的例子,你可以使用可能是这样的:
<LinearLayout 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"
android:orientation="vertical" >
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/counter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0" >
</TextView>
</LinearLayout>
而且竟被代码是这样的:
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView counter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Selects the TextView which holds the value of the counter
this.counter = (TextView) findViewById(R.id.counter);
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
// Sets the initial value of the SeekBar (it must be the same initial
// value of the counter)
seekBar.setProgress(0);
// Sets the max value of the counter
seekBar.setMax(100);
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// This code runs when you scroll the SeekBar to left or right.
// If you scroll to the left, the counter decreases and if you
// scroll to the right, the counter increases
counter.setText(String.valueOf(progress));
}
});
}
}
非常感谢您花时间写这段代码。我目前在应用程序中有这个东西,但看起来有点无聊。所以我决定添加一些看起来不错和有趣的东西,所以我会像水平滚动的东西(或按钮或其他),使UI看起来不错。例如,我们使用圆形水平滚动控件调整收音机。我想让它变成这样。 –
你能证明你的代码?你用什么作为一个水平滚动按钮?一个按钮? SeekBar? – amatellanes
@Adri我不知道我该怎么走。这就是为什么我要求专业人士提供帮助,告诉他们做什么才是正确的方法。 –
好吧,我会构建一段代码,你可能会发现它有帮助。 – amatellanes