在Android中扩展视图类和布局
我正在Android中玩布局和视图。我的布局如下所示:在Android中扩展视图类和布局,android,layout,android-custom-view,Android,Layout,Android Custom View,我正在Android中玩布局和视图。我的布局如下所示: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.mycode.MyView
android:id="@+id/MyView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<LinearLayout
android:id="@+id/leftpane"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_weight="0.95"
android:background="@color/leftpane_background"
android:gravity="center"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay" >
</LinearLayout>
</LinearLayout>
尝试将视图的高度更改为:
android:layout_height="wrap_content"
当您在自定义MyView中重写onMeasure方法时,可能您做了一些错误工作, 因此MyView的所有属性都与父视图匹配。
您能在MyView的onLayout和onMeasure方法中显示您的代码吗。它实际上是一个空的实现:我只调用超类的onDraw()方法。没有其他内容。尝试将您的视图更改为EditText或任何订单标准小部件。我更改了它。如果我使用fill_parent,我会看到一个大的编辑文本视图,而没有其他视图。如果我使用wrap_内容,编辑文本的高度会更小,我可以在屏幕上看到其他布局。我需要一种方法在应用程序的背景上绘制一幅图像(可以随时间变化),但仍在背景上显示布局(按钮、滚动视图等)。如果使用视图来显示活动的背景,然后我认为您可以使用FrameLayout而不是LinearLayout。@MarcoMasci也许您应该使用FrameLayout或merge替换根LinearLayout
android:layout_height="wrap_content"