簡體   English   中英

如何在Android應用程序中設置x,y值?

[英]How to set x,y value in android application?

我是android應用程序的新手,使用textview設置高度和寬度,但我不知道如何在android應用程序中設置x,y值,請幫助我

提前致謝

Here i tried:

 <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select Your country"/>

如果要動態設置width和height,則必須為textview或Android中的任何視圖設置布局參數。

您只能在AbsoluteLayout中使用x和y位置。 像這樣

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content" 
            android:id="@+id/button1" 
            android:layout_x="104dp" 
            android:text="Button" 
            android:layout_y="54dp"></Button>
</AbsoluteLayout>

查看站點中的其他布局

如果IM對,您要設置視圖的高度和寬度(例如textview),則可以在xml布局中進行設置。 例如 :

 <TextView
    android:id="@+id/textView1"
    android:layout_width="DESIRED WIDTH"
    android:layout_height="DESIRED HEIGHT"
    android:text="Select Your country"/>

只需為高度和寬度設置ur值。

或者,如果您想在運行時設置,則可以這樣做

TextView textView =(TextView)findViewById(R.id.textView1);
textView.setWidth(DESIRED WIDTH);
textView.setHeight(DESIRED HEIGHT);

所需的高度和所需的寬度由您決定。

希望對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM