Ste*_*ano 6 android surfaceview android-layout
MyActivity
有setContentView(MySurfaceView)
覆盖所有屏幕.
我想将屏幕分为两个部分:第一2/3屏幕的必须由占据MySurfaceView
最后的1/3通过my_activity_layout.xml
.
我怎样才能做到这一点?谢谢.
编辑
谢谢你的回答,但我没有如何在我的情况下应用它们.要清楚,这些是我的目标:
解决方案:
要在布局中附加xml文件,您可以使用该<include>
标签。
重用布局特别强大,因为它允许您创建可重用的复杂布局。例如,是/否按钮面板,或带有描述文本的自定义进度条。更多的
您可以在 的帮助下拥有问题中所示的功能ConstraintLayout
。当然,有一些解决方案使用<LinearLayout>
传统的权重,但正如警告所述,权重对性能不利。
为什么重量不利于表现?
布局权重需要对小部件进行两次测量。当一个具有非零权重的 LinearLayout 嵌套在另一个具有非零权重的 LinearLayout 中时,测量的数量会呈指数级增长。
那么让我们继续使用 来解决这个问题<ConstraintLayout>
。
假设我们有一个名为的布局文件my_activity_layout.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">
<SurfaceView
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" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.67" />
<include
android:id="@+id/news_title"
layout="@layout/my_activity_layout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,Guideline
帮助我们获得 2/3 即 66.666 ~ 67% 的屏幕,然后您可以使用Activity 上的标签来限制您SurfaceView
和您的布局。<include>
还可以看到需要的结果:
您只需复制粘贴解决方案并查看它是否按预期工作。
归档时间: |
|
查看次数: |
201 次 |
最近记录: |