在Android布局的中心插入ImageView
我使用LinearLayout和RelativeLayout组合创建了一个4矩形布局。现在,我想在前两个布局的中心插入一个黄色图像(配置文件图像),如下图所示: 我不能这样做吗?这是我试过的。这将在开始时正确地设置2个布局在Android布局的中心插入ImageView,android,android-layout,Android,Android Layout,我使用LinearLayout和RelativeLayout组合创建了一个4矩形布局。现在,我想在前两个布局的中心插入一个黄色图像(配置文件图像),如下图所示: 我不能这样做吗?这是我试过的。这将在开始时正确地设置2个布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools&
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darkgreen"
android:orientation="vertical">
<LinearLayout
android:id="@+id/profilenameemailID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".12"
android:orientation="horizontal"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="2dp" >
<RelativeLayout
android:id="@+id/profilelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight=".50"
android:background="@color/light_green"
android:gravity="center" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/namesysmbol"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:visibility="visible" />
<TextView
android:id="@+id/profilenameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/icon"
android:paddingLeft="2dp"
android:text="@string/defaultname"
android:textColor="@color/nametext"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/emailID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight=".50"
android:background="@color/light_green"
android:gravity="center" >
<ImageView
android:id="@+id/eicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/emailsymbol"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:visibility="visible" />
<TextView
android:id="@+id/emailText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/sicon"
android:paddingLeft="2dp"
android:text="@string/defaultEmail"
android:textColor="@color/emailtext"
android:textSize="14sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
有人能帮我用上面的格式在中间插入黄色的图像视图吗
谢谢 你能试着使用这个
布局吗
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="170dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bb4"
android:layout_weight="1"
android:layout_margin="4dp">
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#bb4"
android:layout_margin="4dp">
</LinearLayout>
</LinearLayout>
<!-- Your ImageView here!-->
<View
android:layout_centerInParent="true"
android:layout_width="90dp"
android:layout_height="90dp"
android:background="#ff5"/>
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bb4"
android:layout_weight="1"
android:layout_margin="4dp">
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#bb4"
android:layout_margin="4dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
你能试着使用这个
布局吗
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="170dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bb4"
android:layout_weight="1"
android:layout_margin="4dp">
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#bb4"
android:layout_margin="4dp">
</LinearLayout>
</LinearLayout>
<!-- Your ImageView here!-->
<View
android:layout_centerInParent="true"
android:layout_width="90dp"
android:layout_height="90dp"
android:background="#ff5"/>
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="170dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bb4"
android:layout_weight="1"
android:layout_margin="4dp">
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#bb4"
android:layout_margin="4dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>
这是伪代码,但有助于理解概念
<LinearLayout orientation= vertical>
<FrameLayout>
<LinearLayout orientation= horizontal>
// make to rectangle here
</LinearLayout>
<Image/> create rounded image here with layout_gravity center
</FrameLayout>
<FrameLayout>
<LinearLayout orientation= horizontal>
// make to rectangle here
</LinearLayout>
</FrameLayout>
</LinearLayout>
//在这里做长方形
在此处创建具有布局和重心的圆形图像
//在这里做长方形
这是伪代码,但有助于理解概念
<LinearLayout orientation= vertical>
<FrameLayout>
<LinearLayout orientation= horizontal>
// make to rectangle here
</LinearLayout>
<Image/> create rounded image here with layout_gravity center
</FrameLayout>
<FrameLayout>
<LinearLayout orientation= horizontal>
// make to rectangle here
</LinearLayout>
</FrameLayout>
</LinearLayout>
//在这里做长方形
在此处创建具有布局和重心的圆形图像
//在这里做长方形
复制并粘贴到xml文件中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E3E3E3" >
<RelativeLayout
android:id="@+id/r_1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp" >
<View
android:id="@+id/view1"
android:layout_width="5dp"
android:layout_height="1dp"
android:layout_centerInParent="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/view1"
android:background="#666" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/view1"
android:background="#666" >
</RelativeLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="#ff00ff" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@+id/r_1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp" >
<View
android:id="@+id/view2"
android:layout_width="5dp"
android:layout_height="1dp"
android:layout_centerInParent="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/view2"
android:background="#666" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/view2"
android:background="#666" >
</RelativeLayout>
<ImageView
android:id="@+id/imageView2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="#ff00ff" />
</RelativeLayout>
复制并粘贴到xml文件中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E3E3E3" >
<RelativeLayout
android:id="@+id/r_1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp" >
<View
android:id="@+id/view1"
android:layout_width="5dp"
android:layout_height="1dp"
android:layout_centerInParent="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/view1"
android:background="#666" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/view1"
android:background="#666" >
</RelativeLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="#ff00ff" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@+id/r_1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp" >
<View
android:id="@+id/view2"
android:layout_width="5dp"
android:layout_height="1dp"
android:layout_centerInParent="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/view2"
android:background="#666" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/view2"
android:background="#666" >
</RelativeLayout>
<ImageView
android:id="@+id/imageView2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="#ff00ff" />
</RelativeLayout>
做一件事,用RelativeLayout替换主布局,然后将黄色图像放在包含4个块的布局顶部。做一件事,用RelativeLayout替换主布局,然后将黄色图像放在包含4个块的布局顶部。太好了。谢谢这起作用了。我不得不改变一些参数来满足我的要求。无论如何,谢谢!。伟大的谢谢这起作用了。我不得不改变一些参数来满足我的要求。无论如何,谢谢!。