【问题标题】:Is it possible for two Controllers to have same center两个控制器是否可以具有相同的中心
【发布时间】:2015-08-19 15:08:11
【问题描述】:

Hey Guyz 帮帮我,我遇到了对齐设置问题...我是 Android 开发新手,我想要实现的目标是制作一个音乐播放器,我正在尝试将 ImageView 设置为 ImageButton但是我想将它设置在中心并且我没有找到下面的任何方法是我尝试过的代码..

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageButton
        android:alpha="50"
        android:id="@+id/imageView1"
        android:layout_width="115dp"
        android:layout_height="115dp"
        android:padding="6dp"
        android:src="@drawable/play_btn"
        android:background="@null"
        />
    <ImageView

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/Artist"
        android:layout_above="@+id/textView2"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

这是我尝试过的,但我找不到任何类似的属性 alignWithMatchCenter = "父 ID" 或 centerInParent = "父 ID"

或者如果我可以在 ImageButton Tag 中添加 ImageView 可以吗?

<ImageButton
        android:layout_width="115dp"
        android:layout_height="115dp"
        <ImageView 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/imageView"
          android:src="@drawable/Artist"
          android:layout_above="@+id/textView2"
          android:layout_centerHorizontal="true" />
      />

请帮助我的朋友。 任何帮助将不胜感激。 问候, 萨罗什马达拉

【问题讨论】:

  • "...我想把它放在中心...":我不明白你的意思。你是说你想让ImageView 覆盖ImageButton
  • 是的,我希望两个控制器的中心相同..

标签: java android xml android-layout alignment


【解决方案1】:

你在寻找这样的东西吗:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageButton
        android:id="@+id/imageView1"
        android:alpha="50"
        android:layout_width="115dp"
        android:layout_height="115dp"
        android:padding="6dp"
        android:src="@drawable/play_btn"
        android:layout_centerInParent="true"/>

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/Artist"
        android:layout_centerInParent="true" />

</RelativeLayout>

您可以使用android:layout_centerInParent="true" 让孩子居中。您也可以使用FrameLayout 并设置android:layout_gravity="center"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多