我希望设置一个可绘制的(i.e Vibrator_Button[i])
的大小我尝试使用
drawable.setBounds(0, 0, width, height);
和
MarginLayoutParams params = new MarginLayoutParams(width, height);
它不能使用所有这些另一个令人头痛的问题是它也是一个静态内容,我想知道如何解决这个问题,代码如下,任何解决方案都会非常感激我道歉这可能是一个重复的但我试过所有可能的方式。
Cam_Size = 200;
Segment_Size = 50;
TextSize = 20;
Standard_height = 235;
private static void SetVibratorLayoutDesign() {
Layout_Frame.removeAllViews();
Segments = sharedpreferences.getInt(Vars.Selected_Segment_Count, 0);
int size = Segment_Size + ((16 - (Segments + 1)));
int imageSize = Cam_Size - Segments;
for (int i = 0; i < Segments; i++) {
// Create some quick TextViews that can be placed.
float angleDeg = i * 360.0f / Segments - 90.0f;
float angleRad = (float) (angleDeg * Math.PI / 180.0f);
String VibratorName = Vars.Vibrator_On_Off + "_" + i;
int Current_State = sharedpreferences.getInt(VibratorName, 0);
Vibrator_Button[i] = new ImageButton(act);
TextView SegmentName = new TextView(act);
Vibrator_Lock[i] = new ImageView(act);
SegmentName.setText((i + 1) + "");
if (Current_State == 1) {
Vibrator_Button[i].setImageResource(R.drawable.calibration_camera_on);
} else {
Vibrator_Button[i].setImageResource(R.drawable.calibration_camera_off);
}
Vibrator_Button[i].setBackgroundResource(R.drawable.camera_circle_transparent);
Vibrator_Lock[i].setBackgroundResource(R.drawable.lock);
SegmentName.setGravity(Gravity.CENTER);
SegmentName.setTextColor(Color.BLACK);
SegmentName.setTextSize(TextSize);
SegmentName.setTypeface(null, Typeface.BOLD);
Vibrator_Button[i].setId(Segment_Ids[i]);
Vibrator_Lock[i].setId(Segment_Lock_Ids[i]);
FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(10, 10);
FrameLayout.LayoutParams lp1 = new FrameLayout.LayoutParams(imageSize, imageSize);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(size, size);
lp.gravity = Gravity.CENTER;
lp1.gravity = Gravity.CENTER;
lp2.gravity = Gravity.CENTER;
Vibrator_Button[i].setLayoutParams(lp);
Vibrator_Button[i].setOnClickListener(onClickThis);
Vibrator_Lock[i].setLayoutParams(lp2);
SegmentName.setLayoutParams(lp);
Vibrator_Button[i].setTranslationX(Standard_height * (float) Math.cos(angleRad));
Vibrator_Button[i].setTranslationY(Standard_height * (float) Math.sin(angleRad));
Layout_Frame.addView(Vibrator_Button[i]);
SegmentName.setTranslationX((Standard_height * (float) Math.cos(angleRad)));
SegmentName.setTranslationY((Standard_height * (float) Math.sin(angleRad)) - 5);
Layout_Frame.addView(SegmentName);
Vibrator_Lock[i].setTranslationX((Standard_height * (float) Math.cos(angleRad)));
Vibrator_Lock[i].setTranslationY((Standard_height * (float) Math.sin(angleRad)) + 5);
Layout_Frame.addView(Vibrator_Lock[i]);
}