如何在android工具栏中放置图像?
如何在android中设计此图像中的个人资料图片?我试着把它放在工具栏上,它不会在工具栏下面显示一半 下面是我正在尝试的代码。我在顶部使用线性布局,然后再次使用线性布局来容纳徽标和文本,图像位于根线性布局的底部。尽管设置了边距顶部,但它仍然在那里,并且没有移动到位置:如何在android工具栏中放置图像?,android,xml,responsive-design,Android,Xml,Responsive Design,如何在android中设计此图像中的个人资料图片?我试着把它放在工具栏上,它不会在工具栏下面显示一半 下面是我正在尝试的代码。我在顶部使用线性布局,然后再次使用线性布局来容纳徽标和文本,图像位于根线性布局的底部。尽管设置了边距顶部,但它仍然在那里,并且没有移动到位置: <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:too
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:menu="@menu/action_menu"
android:background="@color/colorPink1"
android:elevation="0dp"
android:layout_margin="0dp"
app:collapseIcon="@drawable/logo_mini"
android:padding="0dp"
android:layout_height="wrap_content" android:minHeight="0dp">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top"
android:orientation="vertical" android:gravity="end" android:dividerPadding="100dp">
<LinearLayout
android:orientation="vertical"
android:id="@+id/main_layout"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:padding="5dp"
android:paddingLeft="50dp"
android:gravity="center">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/center_icon"
android:layout_gravity="center"
android:src="@drawable/logo_mini"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginTop="5dp"
/>
</LinearLayout>
<ImageView
android:layout_marginTop="5dp"
android:id="@+id/bar"
android:src="@drawable/bar"
android:background="@android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="Hi ,"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/emp_name" android:textSize="30sp"/>
<TextView
android:text="Wellcome back,"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/textView5"/>
<TextView android:layout_width="match_parent" android:visibility="gone" android:layout_height="wrap_content"
android:text="here ae you assigned sites"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_gravity="bottom|end"
android:elevation="10dp"
android:src="@drawable/user_photo"
android:layout_alignBottom="@+id/center_icon"
android:layout_width="72dp"
android:layout_height="72dp"
android:gravity='center'
android:layout_marginTop="-50dp"
/>
</android.support.v7.widget.Toolbar>
您可以这样更改布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@color/colorAccent"
android:elevation="0dp"
android:minHeight="0dp"
android:padding="0dp"
app:collapseIcon="@drawable/logo_mini">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:dividerPadding="100dp"
android:gravity="end"
android:orientation="vertical">
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp"
android:paddingLeft="50dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/center_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:src="@drawable/logo_mini" />
</LinearLayout>
<ImageView
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:src="@mipmap/mic" />
<TextView
android:id="@+id/emp_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hi ,"
android:textSize="30sp" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Wellcome back,"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="here ae you assigned sites"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentRight="true"
android:layout_marginTop="80dp"
android:elevation="10dp"
android:gravity='center'
android:src="@drawable/user_photo" />
</RelativeLayout>
尝试使用约束布局来创建响应性用户界面
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StartActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/colorPrimary">
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="24dp"
android:background="@color/colorAccent"
android:src="@drawable/ic_launcher_foreground"
app:layout_constraintBottom_toBottomOf="@+id/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" /></android.support.constraint.ConstraintLayout>
您应该使用
CoordinatorLayout
和layout\u anchor
,layout\u anchorGravity
属性为ImageView
定位工具栏边缘的图像
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@color/colorAccent"
android:elevation="0dp"
android:minHeight="0dp"
android:padding="0dp"
app:collapseIcon="@drawable/logo_mini">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:dividerPadding="100dp"
android:gravity="end"
android:orientation="vertical">
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp"
android:paddingLeft="50dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/center_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:src="@drawable/logo_mini" />
</LinearLayout>
<ImageView
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:src="@mipmap/mic" />
<TextView
android:id="@+id/emp_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hi ,"
android:textSize="30sp" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Wellcome back,"
android:visibility="gone" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="here ae you assigned sites"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/dim150"
android:layout_height="@dimen/dim150"
android:layout_below="@+id/home_txt"
android:layout_marginTop="@dimen/dim20"
android:src="@drawable/user_photo"
app:layout_anchor="@id/toolbar"
app:layout_anchorGravity="bottom|center_horizontal" />
</android.support.design.widget.CoordinatorLayout>
使用边距顶部作为负数,如-50dp,已尝试无效果