Ama*_*rma 7 layout android widget imageview material-components-android
ShapeableImageView 采用 ShapeAppearanceOverlay 样式项来创建所需的形状和大小。形状族被切割和倒圆,半径可以用作数字或百分比。这是我的circularImageView的ShapeAppearanceOverlay主题:
<style name="ShapeAppearanceOverlay.App.circleImageView" parent="">
<item name="cornerFamily">cut</item>
<item name="cornerSize">50%</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这是我使用它的布局:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="240dp" />
<!--Top Header Layout-->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/topbar"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--Top Profile Section -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/user_display_image"
style="@style/ShapeAppearanceOverlay.App.circleImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_user" />
</LinearLayout>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/normal_bottom_margin" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是该问题的屏幕截图:
IDE 截图:
Gab*_*tti 14
使用app:shapeAppearanceOverlay而不是style
<com.google.android.material.imageview.ShapeableImageView
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.circleImageView"
.../>
Run Code Online (Sandbox Code Playgroud)
或者,如果您想通过属性使用它style:
<style name="Style.App.circleImageView" parent="">
<item name="shapeAppearance">@style/ShapeAppearanceOverlay.App.circleImageView</item>
</style>
<style name="ShapeAppearanceOverlay.App.circleImageView" parent="">
<item name="cornerFamily">cut</item>
<item name="cornerSize">50%</item>
</style>
Run Code Online (Sandbox Code Playgroud)
...
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/user_display_image"
style="@style/Style.App.circleImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_user" />
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6202 次 |
| 最近记录: |