Android - 如何使视图仅填充屏幕的其余部分
我有一个自定义视图,旨在表示坐标系。 该视图用于我的一个 xml 文件中。 以下是 xml 文件中的一些内容:
...lots of diff views..
<org.test.ScreenProximityView android:layout_below="@+id/screen_proximity_orix_edit"
android:layout_alignParentLeft="true" android:id="@+id/proxTest"
android:layout_marginTop="70dp" android:layout_height="match_parent"
android:layout_width="match_parent">
</org.test.ScreenProximityView>
</RelativeLayout>
问题是,我希望我的视图仅填充屏幕的其余部分。当我使用 match_parent 时,我得到的视图与屏幕一样大,但一半被剪切到屏幕“外部”。 那么如何调整视图大小以使其仅适合屏幕的其余部分?
编辑:我将像这样在画布上绘制:
public void onDraw(Canvas canvas) {
canvas.drawLine(0, 0, canvas.getWidth(), 0, mPaint);
canvas.drawLine(0, 0, 0, canvas.getHeight(), mPaint);
canvas.drawLine(0, canvas.getHeight(), canvas.getWidth(), canvas.getHeight(), mPaint);
canvas.drawLine(canvas.getWidth(), canvas.getHeight(), canvas.getWidth(), 0, mPaint);
canvas.drawLine(canvas.getWidth()/2, 0, canvas.getWidth()/2, canvas.getHeight(), mPaint);
canvas.drawLine(0, canvas.getHeight()/2, canvas.getWidth(), canvas.getHeight()/2, mPaint);
}
这使得大部分内容都粘在可视屏幕之外。
I have a custom view which is intended to represent a coordinate system.
That view is used in one of my xml-files.
Here's a bit from the xml-file:
...lots of diff views..
<org.test.ScreenProximityView android:layout_below="@+id/screen_proximity_orix_edit"
android:layout_alignParentLeft="true" android:id="@+id/proxTest"
android:layout_marginTop="70dp" android:layout_height="match_parent"
android:layout_width="match_parent">
</org.test.ScreenProximityView>
</RelativeLayout>
The problem is, I want my view to fill the rest of the screen only. When I use match_parent, I get a view that is as big as the screen, but like half gets clipped 'outside' the screen.
So how do I resize my view so it fits the remainder of the screen Only?
EDIT: I am going to draw on its canvas like this:
public void onDraw(Canvas canvas) {
canvas.drawLine(0, 0, canvas.getWidth(), 0, mPaint);
canvas.drawLine(0, 0, 0, canvas.getHeight(), mPaint);
canvas.drawLine(0, canvas.getHeight(), canvas.getWidth(), canvas.getHeight(), mPaint);
canvas.drawLine(canvas.getWidth(), canvas.getHeight(), canvas.getWidth(), 0, mPaint);
canvas.drawLine(canvas.getWidth()/2, 0, canvas.getWidth()/2, canvas.getHeight(), mPaint);
canvas.drawLine(0, canvas.getHeight()/2, canvas.getWidth(), canvas.getHeight()/2, mPaint);
}
Which makes most of the stuff stick otuside the viewable screen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用于
您想要占用剩余空间的视图。使用 LinearLayout 作为父视图。其余的孩子不应该有任何体重。
use
for the view, which you want to occupy the remaining space. works with
LinearLayout
as parent view. and rest of the children shouldn't have any weights.