Android 如何在两种不同布局之间设置“ImageView”

Android 如何在两种不同布局之间设置“ImageView”,android,imageview,android-linearlayout,Android,Imageview,Android Linearlayout,首先我说不出我的问题。因为我的英语学位不足以告诉你这些。所以,检查我的图像以了解我。对了,很抱歉 我想在两个不同的布局之间设置ImageView。您可以看到,第一个布局中没有任何ImageView。第二个是一个红色的框ImageView。如何将其写入布局 这是我的布局代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/r

首先我说不出我的问题。因为我的英语学位不足以告诉你这些。所以,检查我的图像以了解我。对了,很抱歉

我想在两个不同的布局之间设置ImageView。您可以看到,第一个布局中没有任何ImageView。第二个是一个红色的框ImageView。如何将其写入布局

这是我的布局代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
   android:orientation="vertical"
    android:layout_height="match_parent"
    >
<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="160dp"
   android:background="@drawable/porfoy_resmi777" >



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="15dp"
        android:paddingLeft="20dp"

        >
        <TextView
            android:textStyle="bold"
            android:textColor="#FFFFFF"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gönderi:"
            android:layout_marginLeft="60dp"

            />
        <TextView
            android:textStyle="bold"
            android:textColor="#FFFFFF"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Takip edilen"
            android:layout_marginLeft="20dp"
            />
        <TextView
            android:textStyle="bold"
            android:textColor="#FFFFFF"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Takipçi"
            android:layout_marginLeft="20dp"
            />



    </LinearLayout>


    <LinearLayout
        android:layout_marginTop="8dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="75dp"
        android:paddingLeft="25dp"
        >
        <TextView
            android:textStyle="bold"
            android:textColor="#FFFFFF"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0"/>
        <TextView
            android:textStyle="bold"
            android:textColor="#FFFFFF"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0"
            android:layout_marginLeft="87dp"/>

        <TextView
            android:textColor="#FFFFFF"
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0"
            android:layout_marginLeft="70dp" />





    </LinearLayout>









</LinearLayout>





    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="60dp">




        <ImageView
            android:layout_marginLeft="50dp"
            android:id="@+id/telefon_arama_ImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
android:background="@drawable/cla"
            />

        <TextView
            android:id="@+id/telefon_numarasi"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="5"
            android:text="numaram"
            android:layout_marginLeft="20dp"
            android:textStyle="bold"/>
    </LinearLayout>

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="37dp"
    android:orientation="horizontal"
    android:background="@drawable/radyan"
    >

    <ImageView
        android:id="@+id/btn_group"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@drawable/kedi"
        />

    <ImageView
        android:id="@+id/btn_sing"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/bulok"
        />

    <Button
        android:id="@+id/profil_btn_duzenle"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Düzenle"
        android:textAllCaps="false"
        android:textSize="11sp" />


    <Button
        android:id="@+id/profil_cikis"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Çıkış"

        android:textAllCaps="false"
        android:textSize="13sp" />

</LinearLayout>


<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Hakkımda :"
            android:textStyle="bold"
            android:textSize="11dp"/>

        <TextView
            android:id="@+id/Hakkında_bakıs_TextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="14dp"
            android:text="bafbafgfdafadfad"
            android:textStyle="italic|bold"
            />


    </LinearLayout>
</ScrollView>

正如您在屏幕截图中所示,您希望通过放置另一个imageview来重叠imageview,这可以使用相对布局来完成

我将您的根布局更改为RelativeLayout。检查xml您将理解我所做的,这非常简单。如果你有任何问题,让我知道我会写详细的解释

您可以在这里了解更多关于android用户界面设计布局的信息


对此,您应该使用RelativeLayout而不是LinearLayout。线性布局首先沿X水平方向或Y垂直方向使用长子。RelativeLayout沿Z轴排列子对象,即将子对象放置在彼此的顶部。由于需要覆盖图像,因此需要使用RelativeLayout。最简单的方法是将图像放入代码中。快速的谷歌搜索应该会给你几个例子。为了给您一个想法,您需要将根LinerLayout替换为RelativeLayout

// Then get reference to this in code
RelativeLayout rl = (RelativeLayout) findViewById(R.id.my_relative_layout);

// Then you can place your image wherever you want
// You will have to provide the dp values of the coordinates
ImageView iv = new ImageView(this);
iv.setBackgroundColor(Color.RED);
params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 50;
params.topMargin = 60;
rl.addView(iv, params);

下面的stackoverflow答案对此有更多详细信息:

首先;我犯了一个错误。我忘了添加选项卡。在LinearLayout和scrollview区域中,它们是android:background=@drawable/radyan。请您根据我新编辑的问题编辑您的答案。顺便说一下:是的。我不明白你做了什么。你怎么能在相对论中移动直线布局呢?我做到了。谢谢你的回答。但我仍然不明白它是如何工作的。
// Then get reference to this in code
RelativeLayout rl = (RelativeLayout) findViewById(R.id.my_relative_layout);

// Then you can place your image wherever you want
// You will have to provide the dp values of the coordinates
ImageView iv = new ImageView(this);
iv.setBackgroundColor(Color.RED);
params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 50;
params.topMargin = 60;
rl.addView(iv, params);