0

我试图让一个图像旁边有一个按钮,当我运行代码时,我只是在屏幕左侧得到图像,没有按钮,无论我是否首先列出了图像。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:gravity="bottom" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_weight="5"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:contentDescription="@string/none"
        android:src="@drawable/oxwichpointtest" />

    <Button
        android:id="@+id/button1"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:onClick="openGuide"
        android:text="@string/button_text" />

</LinearLayout>

更新:感谢所有建议。我已经全部尝试过了,但我的应用程序布局没有任何变化,所以我怀疑问题在于我如何在 .java 文件中设置图像。我将尝试更改它并希望它会起作用,或者如果我仍然遇到问题,我可以稍后在此处添加代码。再次感谢,至少我知道布局没有什么大问题。

4

3 回答 3

0

您可能在 Layout 声明中缺少一个属性。

android:orientation="horinzontal"

代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:orientation="horinzontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_weight="5"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:contentDescription="@string/none"
        android:src="@drawable/oxwichpointtest" />

    <Button
        android:id="@+id/button1"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:onClick="openGuide"
        android:text="@string/button_text" />

</LinearLayout>
于 2013-07-04T11:23:30.657 回答
0

LinearLayout 缺少 android:orientation 属性?

于 2013-07-04T11:22:11.803 回答
-1

在父级中使用 Android:layout_weight="1" 。

而不是根据您的需要分配重量的部分图像视图和按钮!例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="bottom" android:layout_weight="1">

<ImageView
    android:id="@+id/imageView1"

    android:layout_width="10dp"
    android:layout_height="wrap_content"
    android:contentDescription="@string/none"
    android:src="@drawable/oxwichpointtest" android:layout_weight="0.5"/>

<Button
    android:id="@+id/button1"

    android:layout_width="10dp"
    android:layout_height="wrap_content"
    android:onClick="openGuide"
    android:text="@string/button_text" android:layout_weight="0.5"/></LinearLayout>
于 2013-07-04T11:20:57.663 回答