Android 如何绑定视图';根视图的宽度';s宽度
我希望我的Android 如何绑定视图';根视图的宽度';s宽度,android,xml,android-databinding,Android,Xml,Android Databinding,我希望我的ImageView的宽度与设备屏幕的大小相同。通常,您会将layout\u width属性设置为match\u parent。问题是我的ImageView位于LinearLayout内,而LinearLayout位于水平滚动视图内。请参阅下面的代码 <LinearLayout android:id="@+id/root_layout" android:layout_width="match_parent" android:layout_height=
ImageView
的宽度与设备屏幕的大小相同。通常,您会将layout\u width
属性设置为match\u parent
。问题是我的ImageView
位于LinearLayout
内,而LinearLayout
位于水平滚动视图
内。请参阅下面的代码
<LinearLayout
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:scrollbars="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/fragment_get_trending_image_backdrop1"
android:layout_width='@{String.valueOf(rootLayout.width)+"dp"}'
android:layout_height="200dp"
android:src="@drawable/cassidy"
android:scaleType="fitXY"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
//....other imageviews
你不能做你想做的事。 首先,这可能是一个XY问题。你想要实现什么 您的
root\u布局
有一个边距-android:layout\u margin=“16dp”
,因此它的任何子级都不可能在线性布局中超出其边界
因此,您只需设置android:layout\u margin=“0dp”
(或删除该属性)
此外,您似乎正在
水平滚动视图
中堆叠一堆图像视图
。您可能需要使用RecyclerView
或ViewPager2
。回收器视图似乎可以实现这一目的。感谢您,我试图实现的是让ImageView的宽度与HorizontalScrollView中用户设备的宽度相匹配。
Could not resolve the two-way binding attribute 'width' on type 'android.widget.LinearLayout'