两个控制器是否可以具有相同的中心

时间:2022-11-14 21:26:33

Hey Guyz help me I got stuck with an alignment setting problem... I am new to Android Development and the objective I want to achieve is I am making a Music Player in which I am trying to set an ImageView to an ImageButton but what I want to set it on the center and I did not find any way below is the code which I tried..

嘿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>

This is what I tried but I could not find any property like alignWithMatchCenter = "parent ID" or centerInParent = "parent ID "

这是我尝试但我找不到任何属性,如alignWithMatchCenter =“父ID”或centerInParent =“父ID”

or is it possible if I can add ImageView within ImageButton Tag?

或者我可以在ImageButton标签中添加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" />
      />

please help me friends. Any help will be great appreciated. Regards, Sarosh Madara

请帮帮我的朋友。任何帮助将非常感谢。此致,Sarosh Madara

1 个解决方案

#1


0  

Are you looking for something like this:

你在寻找这样的东西:

<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>

You can use android:layout_centerInParent="true" to center a child. You could also use a FrameLayout and set android:layout_gravity="center".

您可以使用android:layout_centerInParent =“true”来中心孩子。你也可以使用FrameLayout并设置android:layout_gravity =“center”。

#1


0  

Are you looking for something like this:

你在寻找这样的东西:

<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>

You can use android:layout_centerInParent="true" to center a child. You could also use a FrameLayout and set android:layout_gravity="center".

您可以使用android:layout_centerInParent =“true”来中心孩子。你也可以使用FrameLayout并设置android:layout_gravity =“center”。