我在我的LinearLayout中有一個EditText和一個Button,我想將它們緊密排列在一起,讓它們看起來似乎屬於一起(edittext + micButton用於語音輸入)。 現在它們沒有相同的高度,它們並沒有很好地對齊(按鈕看起來比EditText略低)。我知道我可以使用像-5dip這樣的負邊距來讓它們靠得更近,但是有沒有更好的方法來做到這一點?將它們設置在特定的容器/佈局中,以便它們自動具有相同的高度並且它們之間沒有空白。在Android中製作EditText和Button相同的高度
8
A
回答
-1
Android會嘗試自動將所有內容放在文本之外,而不是按鈕本身。
帶我永遠終於搞清楚了。它非常簡單。應該修復它。
myButton.setGravity(Gravity.CENTER_VERTICAL);
或者如果它們在一行中,則將按鈕附加到表格行。
myTableRow.setGravity(Gravity.CENTER_VERTICAL);
0
使用相對佈局就可以拉伸而不知道其它視圖的確切大小取決於另一視圖的大小的圖。 下面是代碼:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:text="button"
android:id="@+id/but"/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/but"
android:layout_alignBottom="@id/but"
android:layout_alignTop="@id/but"
/>
</RelativeLayout>
檢查此鏈接視圖之間減少空間: https://groups.google.com/forum/?fromgroups#!topic/android-developers/RNfAxbqbTIk
0
嗯,不知道爲什麼人不屑這麼多表。
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
注意:由於這兩種觀點都是LinearLayout中(推測方向=水平)內,此命令應該佈局內中心都因爲EditTexts和按鈕可以定位自己的文字略有不同,您可能需要做一些調整(通過更改邊距或填充)以使文本正確對齊。
0
我希望這個解決方案可以幫助您的方案...這裏是代碼..
<RelativeLayout
android:id="@+id/rlLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal"
android:padding="3dp" >
<EditText
android:id="@+id/etId"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#c8c8c8"
android:hint="Edittext"
android:paddingLeft="20dip"
android:paddingRight="10dip"
android:textColor="#000000" />
<RelativeLayout
android:id="@+id/rlLayoutid"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignRight="@+id/etId" >
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginRight="14dp"
android:layout_marginTop="10dp"
android:background="@drawable/calender" />
</RelativeLayout>
</RelativeLayout>
0
@丹尼爾在這裏你可以使用佈局以及重總和
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:weight_sum=2
>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=1
android:text="button"
android:id="@+id/but"/>
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=1
/>
</LinearLayout>
相關問題
- 1. Android:如何將EditText和Button設置爲相同的高度?
- 2. EditText和Button高度問題
- 3. 如何更改EditText和Button的高度?
- 4. 如何在Android中設計EditText和Button
- 5. 製作兩個DIV相同的高度
- 6. Android中EditText和Button的大小問題
- 7. Android - EditText多行強制填充高度
- 8. 如何更改Android中Button的寬度和高度
- 9. 的Android的ImageButton不是的EditText和Button
- 10. 如何在自舉中製作兩個相同高度的列?
- 11. 在同一屏幕上製作2個Android ListViews的高度相同
- 12. Button和EditText檢查
- 13. 在Bootstrap 2.0中製作相同高度的列和垂直對齊標題
- 14. 爲什麼相同的layout_weight導致Android ImageButton和Button的寬度不同?
- 15. 將相同高度設置爲TableLayout的一行中的TextView和EditText?
- 16. 如何在Android中爲Button提供固定的寬度和高度
- 17. Android:自定義視圖,具有相同的寬度和高度
- 18. 具有相同寬度和高度的Android按鈕?
- 19. 可繪製的高度和寬度不工作在Android ICS
- 20. 引導 - 與高度和寬度相同
- 21. 根據Android中的EditText中的文本啓用和禁用Button
- 22. Android相機高度和寬度
- 23. 集DockPanel中的寬度和高度作爲相同WPF窗口的寬度和高度
- 24. 在Android佈局xml文件中放置TextView,EditText和Button
- 25. 製作具有不同高寬比的響應圖像高度相同
- 26. EditText和Button上面TabLayout
- 27. 如何在android中編程設置EditText框的高度和寬度
- 28. 相同高度divs?
- 29. Android:佈局與文字高度相同
- 30. Android限制長度到EditText的寬度