我知道有这样的问题,但大多数时候他们的问题似乎是他们没有将布局对齐为填充父级。好吧,我这样做了,所以我不确定为什么我的按钮仍然无法执行。可能是因为我使用的所有布局?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/face">
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="100dp" android:gravity="center">
<ImageView android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:id="@+id/eyes" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/eyes1" />
<LinearLayout android:layout_marginTop="50dp" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal">
<Button android:id="@+id/eyesback" android:layout_width="50dp" android:layout_height="50dp" />
<Button android:id="@+id/eyesforward" android:layout_height="50dp" android:layout_width="50dp" android:layout_gravity="right"></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
它可能很简单,我也错过了。感谢您的帮助。
最佳答案
试试这个
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/face">
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="100dp" android:gravity="center">
<ImageView android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:id="@+id/eyes" android:background="@drawable/eyes1" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<RelativeLayout android:layout_marginTop="50dp" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal">
<Button android:id="@+id/eyesback" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentLeft="true"/>
<Button android:id="@+id/eyesforward" android:layout_height="50dp" android:layout_width="50dp" android:layout_gravity="right" android:layout_alignParentRight="true"></Button>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
我只是将 LinearLayout 更改为 Relative 布局并将属性设置为一个按钮以从左到右下车。
关于android - 一个按钮在左侧另一个在右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7466331/