Java 布局未正确缩放

Java 布局未正确缩放,java,android,Java,Android,我有7个图像按钮,我正在显示和编辑的xml预览看起来很完美,但当我在模拟器中启动应用程序时,它似乎没有规模,并切断了图像 应该是这样的: -0-0- 0-0-0 -0-0- 其中“0”是按钮。我有一个整体相对布局和三个线性布局设置。首先放置中间,然后顶部和底部与中间对齐 这是我的XML文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schem

我有7个图像按钮,我正在显示和编辑的xml预览看起来很完美,但当我在模拟器中启动应用程序时,它似乎没有规模,并切断了图像

应该是这样的:

-0-0-
0-0-0
-0-0-
其中“0”是按钮。我有一个整体相对布局和三个线性布局设置。首先放置中间,然后顶部和底部与中间对齐

这是我的XML文件

<RelativeLayout 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="horizontal"
android:id="@+id/activity_color_wheel">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:id="@+id/middle_left">

    <ImageButton
        android:id="@+id/dode1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dodecagon1"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground" />

    <ImageButton
        android:id="@+id/dode2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dodecagon2"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground"
        />

    <ImageButton
        android:id="@+id/dode3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dodecagon3"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground" />
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/middle_left"
    android:layout_centerInParent="true"
    android:id="@+id/bottom">

    <ImageButton
        android:id="@+id/dode4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dodecagon4"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground"/>

    <ImageButton
        android:id="@+id/dode5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dodecagon5"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground"/>

</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/middle_left"
    android:layout_centerInParent="true"
    android:id="@+id/top">

    <ImageButton
        android:id="@+id/dode6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dodecagon6"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground"/>

    <ImageButton
        android:id="@+id/dode7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dodecagon7"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground"/>
</LinearLayout>


<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:gravity="center_horizontal"
    android:textSize="25dp" />
</RelativeLayout>


基本上,顶部和底部布局在底部附近被截断。我想我缺少某种缩放特性,但我不确定

所有视图的宽度和高度都是“包裹内容”。
在这种情况下,如果总图像宽度/高度大于屏幕的宽度/高度,它将被切断。
您应该做的是:
1) 将LinearLayouts宽度设置为“匹配父项”。
2) 根据需要为子视图设置权重。
3) 将子项宽度设置为0dp以获得更好的性能。

示例代码段:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:id="@+id/middle_left">

    <ImageButton
        android:id="@+id/dode1"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:src="@drawable/testImage"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground" />

    <ImageButton
        android:layout_weight="1"
        android:id="@+id/dode2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:src="@drawable/testImage"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground"
        />

    <ImageButton
        android:layout_weight="1"
        android:id="@+id/dode3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:src="@drawable/testImage"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground" />
</LinearLayout>


祝你好运。

所有视图的宽度和高度都是“包裹内容”。
在这种情况下,如果总图像宽度/高度大于屏幕的宽度/高度,它将被切断。
您应该做的是:
1) 将LinearLayouts宽度设置为“匹配父项”。
2) 根据需要为子视图设置权重。
3) 将子项宽度设置为0dp以获得更好的性能。

示例代码段:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:id="@+id/middle_left">

    <ImageButton
        android:id="@+id/dode1"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:src="@drawable/testImage"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground" />

    <ImageButton
        android:layout_weight="1"
        android:id="@+id/dode2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:src="@drawable/testImage"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground"
        />

    <ImageButton
        android:layout_weight="1"
        android:id="@+id/dode3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:src="@drawable/testImage"
        android:onClick="selected"
        android:background="?android:attr/selectableItemBackground" />
</LinearLayout>



祝你好运。

如果你的问题只是顶部和底部图像,那么你只需要添加一个
ScrollView
作为你的
RelativeLayout
的父级,如果你的问题只是顶部和底部图像,然后,您只需要添加一个
滚动视图
作为您的
RelativeLayout

的父视图,如果视图的高度超过屏幕高度,则这将为视图添加一个滚动选项。理想情况下,我希望它能为每个屏幕缩放,而不必滚动使用它,然后您应该使用权重并添加adjustViewBounds=“true”如果视图的高度超过屏幕高度,这将在视图中添加一个滚动选项。理想情况下,我希望它可以缩放每个屏幕,而不必滚动使用它。然后,您应该使用权重并将adjustViewBounds=“true”添加到图像中,但如果视图在顶部/底部被截断,这不是高度而不是宽度吗?我需要切换高度和宽度吗?不需要。当您将“重量”和“宽度”设置为0时,您基本上是在告诉布局您希望让重量分布为您设置宽度。这对于线性布局是正确的。因此,如果您想将图像的高度设置为“不剪切”,那么如果父级包含的是线性布局,您也应该执行相同的操作。在您的情况下,关于高度问题,您的父布局是相对的。因此,您应该做的只是将相关属性(如**layout\u below**)设置为所有布局之间的引用,以及将引用设置为父视图(如layout\u alignParentTop)。可能有3个单独的线性布局,两个引用另一个布局?当然,只要它们都是同一父级相对布局的直接子级,那么如果它在顶部/底部截断,那不是高度而不是宽度吗?我需要切换高度和宽度吗?不需要。当您将“重量”和“宽度”设置为0时,您基本上是在告诉布局您希望让重量分布为您设置宽度。这对于线性布局是正确的。因此,如果您想将图像的高度设置为“不剪切”,那么如果父级包含的是线性布局,您也应该执行相同的操作。在您的情况下,关于高度问题,您的父布局是相对的。因此,您应该做的只是将相关属性(如**layout\u below**)设置为所有布局之间的引用,以及将引用设置为父视图(如layout\u alignParentTop)。可能有3个单独的线性布局,两个引用另一个布局?当然,只要它们都是同一父级相对布局的直接子级。如果答案对您有帮助,请将其标记为解决方案。谢谢。如果答案对您有帮助,请将其标记为解决方案。谢谢