简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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