Android - 如何使视图仅填充屏幕的其余部分

发布于 2024-12-11 02:06:21 字数 1203 浏览 0 评论 0原文

我有一个自定义视图,旨在表示坐标系。 该视图用于我的一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追风人 2024-12-18 02:06:21

用于

android:layout_weight = "1"

您想要占用剩余空间的视图。使用 LinearLayout 作为父视图。其余的孩子不应该有任何体重。

use

android:layout_weight = "1"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文