我想設置一個文本框,但我希望它在多個設備上,並且只佔用屏幕上70%的空間。我可以這樣做嗎?如何將Android文本框設置爲僅佔用XML總寬度的60%?
1
A
回答
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%的寬度應用任何尺寸的屏幕都很有用 –
相關問題
- 1. 如何將flexbox寬度僅設置爲
- 2. Android設置edittext的文本寬度? setTextSize僅適用於高度,爲什麼?
- 3. 如何將背景設置爲100%寬度,同時將文本內的文字設置爲其他寬度?
- 4. 如何設置寬度爲PowerPoint文本框未定義
- 5. 文本佔用設置寬度圖像旁邊的剩餘寬度
- 6. 如何將文本框的寬度設置爲與ASP.NET中的MaxLength相同
- 7. jqtransform - 設置文本框寬度
- 8. 如何將鉛筆中的富文本框設置爲自定義寬度?
- 9. 如何將DataTemplate的寬度設置爲Listbox的寬度?
- 10. 如何將p:carousel寬度設置爲100%?
- 11. 如何將div寬度設置爲100%
- 12. 如何在ASP.NET MVC中設置HTML Helper文本框的寬度?
- 13. 如何在asp.net mvc 3中設置文本框的寬度?
- 14. 如何在WPF中設置一個文本框的寬度?
- 15. 如何使用像素設置寬度的文本框,沒有溢出文本?
- 16. CSS文本寬度設置
- 17. 如何強制TextView將寬度更改爲Android中文本的寬度
- 18. 如何將文本塊設置爲自動調整爲TreeView的寬度?
- 19. 如何將datagridview的行/列寬設置爲datagridview的寬度?
- 20. 如何將ToggleButton寬度設置爲更寬的textOn和textOff值?
- 21. 如何設置ZK組合框寬度
- 22. 根據超級視圖的總寬度設置文本大小
- 23. 將高度和寬度設置爲img
- 24. 如何在HTML中將div的寬度/高度設置爲100%
- 25. 如何將寬度設置爲自舉類型下的輸入文本字段
- 26. 如何將焦點設置爲僅插入到我的頁面的文本框?
- 27. 如何將圖像寬度設置爲100%,高度自動設置爲原生?
- 28. 如何在Android中爲不同的屏幕尺寸寬度設置文本視圖寬度?
- 29. 如何使用'style'選項在CakePHP中設置文本框的寬度?
- 30. 如何在Android中爲按鈕設置寬度和高度?
你講述的TextView或EditText? –