And*_*rew 8 android scrollview relativelayout
我的一个屏幕上有一个ScrollView.我希望右边有阴影.我决定最简单的方法是让ScrollView的子项成为RelativeLayout,并有两个RelativeLayout的子项 - 一个是LinearLayout,它将容纳屏幕的布局,第二个View是阴影.
像这样......
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- stuff -->
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/shadow"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不太有效.ImageView强制其尺寸为图像文件的大小.它不会垂直拉伸成RelativeLayout的高度.我也试过"match_parent"无济于事.图像是9补丁.
想法?
Dev*_*red 20
应用可绘制内容作为ImageView某种程度的来源有一个固有的要求,即您希望视图尽其所能来容纳内容而不必非常修改内容本身.通常,这是您想要的行为ImageView.
您真正想要的是通过将可绘制内容设置为background视图的行为,您根本不需要它ImageView.背景设计为简单地拉伸,填充等等视图的大小.此外,由于您正在使用,RelativeLayout您可以通过添加id一些额外的layout_align参数来告诉视图匹配您正在视图的视图的边界.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/content_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- stuff -->
</LinearLayout>
<View
android:layout_width="11dp"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/content_layout"
android:layout_alignBottom="@id/content_layout"
android:background="@drawable/shadow"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
试试这个
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@drawable/ic_launcher"
android:scaleType="fitXY"
android:layout_alignParentRight="true"
/>
Run Code Online (Sandbox Code Playgroud)
这就是我得到的

和代码ID
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- stuff -->
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:background="@drawable/ic_launcher"
android:scaleType="fitXY" />
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15634 次 |
| 最近记录: |