我想在屏幕中心有一个文本视图,其中有许多自定义 SeekBars 位于一个圆圈的边缘周围。它应该看起来像这样。
这是我到目前为止的代码。为了使用更少的代码而不是自定义的 SeekBars,我将使用默认的 SeekBars。我正在使用 Vertical Seek Bar 库https://github.com/AndroSelva/Vertical-SeekBar-Android
主要活动:
public class MainActivity extends Activity implements OnSeekBarChangeListener {
TextView tv;
TextView ss;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.main_layout);
tv = (TextView)findViewById(R.id.seek_score);
ss = (TextView)findViewById(R.id.selected_segment);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.RIGHT_OF, tv.getId());
VerticalSeekBar verticalSeekBar = (VerticalSeekBar) getLayoutInflater().inflate(R.layout.motif_segment, null);
verticalSeekBar.setName("Test Segment");
verticalSeekBar.setOnSeekBarChangeListener(this);
layout.addView(verticalSeekBar, lp);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return false;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean isUser) {
tv.setText(Integer.toString(progress / 100));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}
main_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:id="@+id/main_layout"
android:layout_gravity="center"
>
<TextView
android:id="@+id/seek_score"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerHorizontal="true"
android:background="@drawable/circle"
android:gravity="center"
android:text="0"
android:layout_margin="40dip"
/>
<TextView
android:id="@+id/selected_segment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="" />
</RelativeLayout>