简体   繁体   English

如何在Android应用程序中设置x,y值?

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

I am new to android application, using textview to set height and width but i didnot know how to set x,y value in android application, please help me 我是android应用程序的新手,使用textview设置高度和宽度,但我不知道如何在android应用程序中设置x,y值,请帮助我

Thanks in Advance 提前致谢

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中的任何视图设置布局参数。

You can use x and y position in AbsoluteLayout only. 您只能在AbsoluteLayout中使用x和y位置。 Like this 像这样

<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>

See other layouts in this site 查看站点中的其他布局

If IM Right that u want to set the height and width of a view(say textview) You can do so in the xml layout. 如果IM对,您要设置视图的高度和宽度(例如textview),则可以在xml布局中进行设置。 for example : 例如 :

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

just set ur value for height and width. 只需为高度和宽度设置ur值。

Or if u want to set in in run time u can do it like that 或者,如果您想在运行时设置,则可以这样做

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

DESIRED HEIGHT & DESIRED WIDTH is up to you. 所需的高度和所需的宽度由您决定。

hope it help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM