android - 我如何在android中绘制一个矩形并在其中放置一些文本然后放置它?

标签 android draw

您好,我有一个 Activity ,在 Activity 中我有一些按钮和 TextView ,我想绘制一个包含文本的矩形。我在网上看到了一些示例,但都说要创建我的 on view ,覆盖 onDraw 并将此 View 设置为我的布局,但我已经有了我的布局。

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView baramzona = (TextView) findViewById(R.id.TextView01);
    baramzona.setText(R.string.baram_zona_textview);
    final Button pocniparking = (Button) findViewById(R.id.ButtonStart);
    final TextView momentalnazona = (TextView) findViewById(R.id.TextView02);



    //momentalnazona.setText("Моментално се наоѓате во зоната");
    pocniparking.setText(R.string.btn_Start_Parking);
    pocniparking.setEnabled(false);

    }
  }

有什么想法吗?

最佳答案

这是一种解决方法,但它适合我的目的。基本上,您可以将 TextView 放在表格中,设置轮廓的表格背景和轮廓大小的边距。希望对您有所帮助。

<TableLayout android:id="@+id/TableLayout01"
   android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:background="#55771B">
 <TextView android:text="@+id/TextView01"
 android:id="@+id/TextView01"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginLeft="3px"
 android:layout_marginBottom="3px"
 android:layout_marginRight="3px"
 android:layout_marginTop="3px"
 android:background="#010101"/>
</TableLayout>

关于android - 我如何在android中绘制一个矩形并在其中放置一些文本然后放置它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3325883/

相关文章:

c# - 填充二维矩形

android - 我有一个线性布局和一个框架布局,我在框架布局中膨胀我的 fragment ,如何从 fragment 访问线性布局

Java 绘制图像方法

javascript - 在 Canvas 上绘制像素并使用多个符号读取位置和颜色?

android - OpenGL ES 2.0 的漫反射着色器 : Light changes with camera movement (Vuforia on Android)

python - 在 Caffe 中绘制网络时出错

c# - 用C#在图片上写文字

android - 如何在TextView中显示数据

android - 如何在 Android 应用程序中安全地存储凭据(密码)?

Android - 应用内结算和现有客户