3
A
回答
8
使用父爲LinearLayout
和使用weightSum
和weight
屬性
樣品
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >
<RelativeLayout
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50" >
<!-- Your RelativeLayout Items -->
</RelativeLayout>
</LinearLayout>
0
*@SuppressLint("NewApi")
public static int getDeviceWidth(Activity activity) {
int deviceWidth = 0;
Point size = new Point();
WindowManager windowManager = activity.getWindowManager();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
windowManager.getDefaultDisplay().getSize(size);
deviceWidth = size.x;
} else {
Display display = windowManager.getDefaultDisplay();
deviceWidth = display.getWidth();
}
return deviceWidth;
}
@SuppressLint("NewApi")
public static int getDeviceHeight(Activity activity) {
int deviceHeight = 0;
Point size = new Point();
WindowManager windowManager = activity.getWindowManager();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
windowManager.getDefaultDisplay().getSize(size);
deviceHeight = size.y;
} else {
Display display = windowManager.getDefaultDisplay();
deviceHeight = display.getHeight();
}
return deviceHeight;
}*
上述兩個功能是獲取設備的高度和寬度。
使用此功能,可以獲得屏幕大小的一半。
我希望它對你有用。
1
你需要把RelativeLayout
一個LinearLayout
內使用android:weightsum=2
和android:layout_weight=1
以獲得所需的比例
<?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"
android:orientation="horizontal"
android:weightSum="2" >
<RelativeLayout
....
android:layout_weight=1
....>
</RelativeLAyout>
</LinearLayout>
2
劃分的相對佈局成兩個相等的相對佈局
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
</RelativeLayout>
和分割的線性佈局成兩個相等的相對佈局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
</LinearLayout>
相關問題
- 1. 設置android的相對佈局的高度和寬度
- 2. 如何將相對佈局的子視圖的高度設置爲總屏幕高度的百分比
- 3. 根據屏幕高度設置佈局
- 4. 在xml中創建一個寬度和高度爲屏幕一半的對象
- 5. 如何設置相對佈局的高度和寬度百分比
- 6. Android |獲取屏幕高度,寬度和屏幕寬度,高度
- 7. iOS的自動佈局來設置寬度和高度根據屏幕大小
- 8. 將div的高度設置爲任意寬度的一半
- 9. 擬合的ImageView屏幕高度和全屏幕寬度的一半
- 10. 屏幕寬度和高度
- 11. 如何設置與屏幕高度相同的div的高度
- 12. 如何設置適合任何屏幕高度的佈局?
- 13. Android,佈局屏幕寬度
- 14. 如何設置屏幕高度一半的視圖?
- 15. Primefaces對話框設置高度的一半屏幕尺寸
- 16. 如何爲電視設置任何佈局(寬度,高度)?
- 17. Xcode:將UIView高度和寬度設置爲SuperView(主視圖)的一半高度和寬度
- 18. 將relativelayout的寬度設置爲屏幕寬度的1/3?
- 19. 如何爲小屏幕和大屏幕設置webview寬度
- 20. 如何獲得iOS設備屏幕的高度和寬度
- 21. 在基於設備屏幕寬度/高度的佈局中指定視圖的相對維度
- 22. 屏幕的高度和寬度
- 23. 錯誤的屏幕寬度和高度
- 24. 如何定義屏幕高度的佈局元素高度
- 25. 將高度和寬度設置爲img
- 26. 如何將對話主題活動寬度設置爲屏幕寬度?
- 27. Android的線性佈局的高度和寬度沒有設置
- 28. 將寬度和高度設置爲div的位置:absolute絕對
- 29. 將元素的高度設置爲屏幕高度 - Angular2
- 30. 調節寬度的一半屏幕
使用重量概念 – jyomin
@varghesekutty你必須屏幕的一半heght寬度根據你的問題,我的答案是正確的。請不要減去積分 – dipali
@dipali謝謝你的回答 – varghesekutty