【问题标题】:Cornering button to bottom left android左下角的转向按钮android
【发布时间】:2014-11-28 05:26:53
【问题描述】:

我正在尝试制作一个与 CandyCrush 完全相同的菜单:中间有两个按钮(播放和连接),然后在左下方,还有另一个按钮(CC 的箭头)。我设法将第一个按钮放置在按钮上,但我无法将最后一个按钮放置在活动的左下方。我该如何定位它?这是我的 xml,我使用相对布局。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ImageView
    android:id="@+id/balao"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:adjustViewBounds="true"  
    android:scaleType="fitCenter"  
    android:background="@null"
    android:maxWidth="200dp"  
    android:maxHeight="180dp"
    android:layout_weight="1"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="35dp"
    android:src="@drawable/balao" />
<ImageButton
    android:id="@+id/play"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:layout_centerHorizontal="true"
    android:maxWidth="80dp"  
    android:maxHeight="80dp"
    android:background="@android:color/transparent"   
    android:layout_below="@+id/balao"
    android:layout_weight="1"
    android:layout_marginBottom="10dp"
    android:src="@drawable/playbutton" />
<ImageButton
    android:id="@+id/tutor"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:layout_below="@+id/play"  
    android:layout_centerHorizontal="true"
    android:maxWidth="50dp"  
    android:maxHeight="50dp"
    android:background="@android:color/transparent"   
    android:layout_weight="1"
    android:src="@drawable/tutor" />

<ImageButton
        android:id="@+id/corner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:src="@drawable/corner"/>
</RelativeLayout>

【问题讨论】:

  • 请问可以发截图吗?
  • 好吧,问题解决了,确实是 wrapcontent/fillparent 的问题。顺便说一句,我怎样才能将这两个答案都评为最佳?
  • 非常感谢您的帮助。
  • 您可以为所有答案投票并选择您认为有帮助的答案。

标签: java android xml android-layout android-relativelayout


【解决方案1】:

对于最后一个按钮,使用android:layout_width="wrap_content" 而不是android:layout_width="fill_parent"

即:

<ImageButton
    android:id="@+id/corner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:adjustViewBounds="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:src="@drawable/corner"/>

【讨论】:

    【解决方案2】:

    权重属性在 RelativeLayout 中不适用,因此请从 xml 中删除:

    android:layout_weight="1" // remove this properties
    

    将底部按钮设置为左侧简单设置宽度为换行而不是填充:

     android:layout_width="wrap_content"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多