【发布时间】:2016-01-28 15:46:12
【问题描述】:
我正在尝试在屏幕顶部显示一个扩展 View 的类,并在 xml 布局中显示两个 texviews 和它下方的一个按钮,但要么只显示视图而没有下面的按钮,要么只显示下面的视图和按钮如果我将视图高度硬编码为 400dp,则会显示,任何帮助将不胜感激,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<view class="....MyView"
android:id="@+id/myView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" //"400dp"
/>
<LinearLayout
android:id="@+id/graphCntrls"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/myView"
>
<TextView
android:id="@+id/tvXCoord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:text="x coordinate"/>
<TextView
android:id="@+id/tvYCoord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:text="y coordinate"/>
<Button
android:id="@+id/coordsCalcBttn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:text="Calc" />
</LinearLayout>
</RelativeLayout>
【问题讨论】:
-
也许 myview.wrap_content 填满了整个屏幕,这就是问题所在?如何设置 MyView 的视图高度?
-
我没有设置 MyView 的高度,它的构造函数是这样定义的 public MyView(Context context, AttributeSet attr) { super(context, attr);} 并且它覆盖了 onDraw(Canvas canvas)
-
抱歉回复晚了,我也试过把layout_height改成match_parent和fill_parent,还是没有显示下面的小部件
-
您是否尝试过将父外部布局设置为垂直线性布局,而不是为此使用相对布局?
-
我只是做了,没有任何变化