Java 在另一个视图周围的圆圈中动态添加视图
我想在屏幕的中心有一个文本视图,在一个圆的边缘周围有许多自定义的搜索键。应该是这样的 这是我到目前为止的代码。为了使用更少的代码而不是自定义seekbar,我将使用默认seekbar。我正在使用垂直搜索栏库 main活动:Java 在另一个视图周围的圆圈中动态添加视图,java,android,android-layout,android-view,Java,Android,Android Layout,Android View,我想在屏幕的中心有一个文本视图,在一个圆的边缘周围有许多自定义的搜索键。应该是这样的 这是我到目前为止的代码。为了使用更少的代码而不是自定义seekbar,我将使用默认seekbar。我正在使用垂直搜索栏库 main活动: public class MainActivity extends Activity implements OnSeekBarChangeListener { TextView tv; TextView ss; @Override protected v
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>
我想在屏幕中央有一个文本视图,其中包含许多
围绕圆中的边定位的自定义搜索栏
如果编号的视图具有任意尺寸(menaing它们比中心圆大),并且您只想将它们像您的图像一样放置,那么就非常简单:
- 创建圆形视图,该视图将是一个正方形,边的距离介于4和2之间或3和1之间,以父视图为中心
- 视图1将水平居中,并设置在圆形视图上方
- 视图3将水平居中,并设置在圆形视图下方
- 视图4将垂直居中并设置在圆形视图的左侧
- 视图2将垂直居中,并设置在圆形视图的右侧
视图组
,以更精确地计算子视图的放置方式
我想在屏幕中央有一个文本视图,其中包含许多
围绕圆中的边定位的自定义搜索栏
如果编号的视图具有任意尺寸(menaing它们比中心圆大),并且您只想将它们像您的图像一样放置,那么就非常简单:
- 创建圆形视图,该视图将是一个正方形,边的距离介于4和2之间或3和1之间,以父视图为中心
- 视图1将水平居中,并设置在圆形视图上方
- 视图3将水平居中,并设置在圆形视图下方
- 视图4将垂直居中并设置在圆形视图的左侧
- 视图2将垂直居中,并设置在圆形视图的右侧
如果这四个视图不是要围绕圆放置的单个视图,则应创建一个自定义
视图组
,以更精确地计算子视图的放置方式。谢谢我花了时间让它工作,但你的建议很到位。谢谢我花了时间让它工作,但你的建议很到位。