缩放 ImageView 以适应重叠的 ToolBar
Scale ImageView to fit ToolBar with overlap
我想将 ImageView 居中放置在我的 ToolBar 顶部并使其重叠。
它应该是这样的:
黑色矩形应该是工具栏,带半圆的灰色矩形是我想放在工具栏顶部的 ImageView,这样 半圆就会重叠工具栏。
我的工具栏是这样的:
<?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
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/actionbar_bg"
/>
</RelativeLayout>
现在,如果我将 ImaveView 放在顶部,它就太大了:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_centerHorizontal="true"
android:src="@drawable/addbtn_bg"
android:adjustViewBounds="true"
/>
但是如果我设置它 android:layout_alignBottom="@id/toolbar"
那么它就完全适合但是半圆不重叠:
有什么办法可以做到这一点吗?
也许通过使用诸如指南之类的东西来仅使 ImageView 的矩形部分对齐?
谢谢。
我认为你必须有一个单独的半圆,它使用 below="@id/toolbar"
好的,我们解决了。
使用 matty357 中的提示,我将 ImageView 更改为两个单独的 ImageView(矩形和半圆形),而不是为矩形 ImageView 分配 src 属性,我使用此文件使其采用背景属性:
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<nine-patch
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/title_bar_9"
android:dither="true"
/>
</item>
</layer-list>
它使用 9-Patch Image 也可以缩小它。
现在就像一个魅力!谢谢!
我想将 ImageView 居中放置在我的 ToolBar 顶部并使其重叠。
它应该是这样的:
黑色矩形应该是工具栏,带半圆的灰色矩形是我想放在工具栏顶部的 ImageView,这样 半圆就会重叠工具栏。
我的工具栏是这样的:
<?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
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/actionbar_bg"
/>
</RelativeLayout>
现在,如果我将 ImaveView 放在顶部,它就太大了:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_centerHorizontal="true"
android:src="@drawable/addbtn_bg"
android:adjustViewBounds="true"
/>
但是如果我设置它 android:layout_alignBottom="@id/toolbar"
那么它就完全适合但是半圆不重叠:
有什么办法可以做到这一点吗? 也许通过使用诸如指南之类的东西来仅使 ImageView 的矩形部分对齐?
谢谢。
我认为你必须有一个单独的半圆,它使用 below="@id/toolbar"
好的,我们解决了。 使用 matty357 中的提示,我将 ImageView 更改为两个单独的 ImageView(矩形和半圆形),而不是为矩形 ImageView 分配 src 属性,我使用此文件使其采用背景属性:
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<nine-patch
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/title_bar_9"
android:dither="true"
/>
</item>
</layer-list>
它使用 9-Patch Image 也可以缩小它。 现在就像一个魅力!谢谢!