Java Android:如何按父视图剪裁视图,如CSS overflow:hidden
我的意见如下:Java Android:如何按父视图剪裁视图,如CSS overflow:hidden,java,android,css,xml,android-view,Java,Android,Css,Xml,Android View,我的意见如下: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/global_legal_gap" android:clipToPadding="true" android:clipChildren="true" android:baselineAlig
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/global_legal_gap"
android:clipToPadding="true"
android:clipChildren="true"
android:baselineAligned="false"
android:background="@drawable/post_sound_bg"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="@dimen/post_sound_card_height"
android:layout_height="@dimen/post_sound_card_height">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/album_art"
android:layout_width="@dimen/post_sound_card_height"
android:layout_height="@dimen/post_sound_card_height"
fresco:backgroundImage="@drawable/music_placeholder" />
<RelativeLayout
android:id="@+id/play_icon_control"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:visibility="gone">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="3dp" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout>
如父级RelativeLayout
所示,我使用的是android:clipToPadding=“true”
和
android:clipChildren=“true”
,但此父视图的子视图仍在其外部突出
还是我做对了?如何实现CSS的溢出:隐藏?考虑更改布局。您可以使用
ConstraintLayout
完成所需的操作
只需设置布局的尺寸,不要在要溢出/隐藏的零件上设置约束
下面的代码显示了一个视图
,该视图根据约束调整其尺寸,另一个视图溢出
创建一个新的android项目并将其粘贴为activity\u main.xml
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity"
android:layout_margin="55dp">
<ImageView
android:id="@+id/imageView3"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:drawable/sym_def_app_icon"/>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="84dp"/>
<ImageView
android:id="@+id/imageView4"
android:layout_width="0dp"
android:layout_height="300dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline"
app:srcCompat="@mipmap/ic_launcher"/>
</android.support.constraint.ConstraintLayout>
您的父视图
android:layout_width="match_parent"
android:layout_height="wrap_content"
这意味着,如果子视图足够大,则该视图将采用所有可用宽度,最高可达所有可用高度。使用此设置,您无法看到溢出:隐藏的行为,因为父级将调整自身大小以包含整个屏幕大小的子级
实际上,android中的默认视图行为类似于overflow:hidden
要查看它,需要在父对象上设置固定的维度
试着用以下方法:
<LinearLayout
android:layout_width="20dp"
android:layout_height="20dp"
您是否尝试过adjustViewBounds=“true”?@harshjain`adjustViewBounds`用于图像,除此之外,它甚至不用于图像,而是用于纵横比。代码中没有android:cliptoppadding
。你可以发布你想要的东西的草图吗?@TadijaBagarić代码只是被格式不好的代码删掉了,请参见编辑。你是否尝试过将android:layout_height设置为match_parent
?如果可以用我上面发布的内容来完成,我会很高兴的。在改变任何事情之前,我想了解为什么这不起作用。