【发布时间】:2018-11-16 23:36:04
【问题描述】:
我正在使用带有 weightSum 的 LinearLayout,因此我可以设计通用屏幕以在所有屏幕尺寸上运行。也许我无法正确理解 wrap_content 和 match_parent 属性。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.hbss.hybridsoftwaresolutions.rashidfaheem.mysecondapplication.easypercentagecalculator.MainActivity"
tools:showIn="@layout/activity_main"
android:orientation="vertical"
android:weightSum="10"
android:background="#0d001c"
>
<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
</View>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="5"
>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/image01"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Percent Calculator"
android:textSize="15dp"
android:layout_weight="3"
android:id="@+id/btnPCalculator"
/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</View>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="5"
>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/image04"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Percent Increase"
android:textSize="15dp"
android:layout_weight="3"
android:id="@+id/btnPIncrease"
/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</View>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="5"
>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/image05"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Percent Decrease"
android:textSize="15dp"
android:layout_weight="3"
android:id="@+id/btnPDecrease"
/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</View>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="5"
>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/image02"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Tip Calculator"
android:textSize="15dp"
android:layout_weight="3"
android:id="@+id/btnTCalculator"
/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</View>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="5"
>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/image03"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Percent Margin"
android:textSize="15dp"
android:layout_weight="3"
android:id="@+id/btnPMargin"
/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</View>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="5"
>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/image06"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Percentage Change"
android:textSize="15dp"
android:layout_weight="3"
android:id="@+id/btnPChange"
/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</View>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="5"
>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/image07"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Percentage (what % of)"
android:textSize="15dp"
android:layout_weight="3"
android:id="@+id/btnPWhatof"
/>
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</View>
</LinearLayout>
</LinearLayout>
【问题讨论】: