如何将Android文本框设置为仅占XML总宽度的60%?

如何将Android文本框设置为仅占XML总宽度的60%?,android,xml,Android,Xml,我想设置一个文本框,但我希望它在多个设备上,并且只占用屏幕上70%的空间。我可以这样做吗?嗨,用xml试试这种方法 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" an

我想设置一个文本框,但我希望它在多个设备上,并且只占用屏幕上70%的空间。我可以这样做吗?

嗨,用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> 

您好,请在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> 

使用android:padding=“yourvaluespx”

PX是yourvalues插入任意数字时的值

使用android:padding=“yourvaluespx”


PX是您的值插入任意数字

在其旁边添加一个空的
线性布局
,将两个
布局宽度
都设置为0dp。然后将
文本视图
(或
编辑文本
)和
线性布局的权重分别设置为0.7和0.3

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

在其旁边添加一个空的
线性布局
,将两个
布局宽度设置为0dp。然后将
文本视图
(或
编辑文本
)和
线性布局的权重分别设置为0.7和0.3

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

请尝试以下操作:

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


int int_var = (width * 60)/100;
并将
int\u var
作为宽度

请尝试以下操作:

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


int int_var = (width * 60)/100;

并将
int\u var
作为宽度

您是否在讲述textView或EditText?您是否在讲述textView或EditText?这对于以60%宽度应用任意大小的屏幕非常有用这对于以60%宽度应用任意大小的屏幕非常有用