2011-09-08 61 views

回答

4

喜嘗試這種方式在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> 
0

採用Android:填充= 「yourvaluespx」;

PX是yourvalues值插入任意數量的

0

添加旁邊有一個空LinearLayout,同時設置Layout Width到0dp。然後分別設置TextView(或EditText)和LinearLayout以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> 
0

請嘗試這種::

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


int int_var = (width * 60)/100; 

,並把int_var爲寬度

+0

這對於以60%的寬度應用任何尺寸的屏幕都很有用 –

相關問題