开发者

How can I set an Android text box to only take up 60% of the overall width in XML?

开发者 https://www.devze.com 2023-04-03 23:21 出处:网络
I want to set up a text box开发者_开发问答, but I want it on multiple devices and to only take up 70% of the room on the screen. Can I do this?hi try this way in xml

I want to set up a text box开发者_开发问答, but I want it on multiple devices and to only take up 70% of the room on the screen. Can I do this?


hi try this way in xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:weightSum="10" 
    android:id="@+id/commonlayout" > 

          <TextView android:id="@+id/tvlogin"    
           android:layout_height="fill_parent"  
           android:text="My Text View in 60%"  
         android:layout_width="0dp"               
        android:layout_weight="6"> 
         </TextView> 
</LinearLayout> 


use android:padding = "yourvaluespx";

PX is the value at yourvalues insert any number


Add a empty LinearLayout beside it, set both Layout Width to 0dp. Then set the weight of TextView (or EditText) and the LinearLayout to 0.7 and 0.3 respectively

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
    <LinearLayout android:layout_height="match_parent" android:id="@+id/linearLayout1" android:layout_weight="0.3" android:layout_width="0dp"></LinearLayout>
    <TextView android:text="TextView" android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_weight="0.7" android:layout_width="0dp"></TextView>
</LinearLayout>


please try this::

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();


int int_var = (width * 60)/100;

and put int_var as width

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号