【发布时间】:2015-03-16 21:01:09
【问题描述】:
我的布局必须是这样的。这是 android studio 渲染。
这个问题出现在所有类型的模拟器上。还在真正的 Nexus 5 上对其进行了测试,效果很好。可能是什么问题?
更新
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/content_layout" >
<LinearLayout
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/func_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@drawable/border_right"
android:orientation="vertical"
android:paddingRight="@dimen/function_layout_padding" >
</LinearLayout>
<RelativeLayout
android:id="@+id/graph_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#FFF"
android:alpha="0.0"
android:layout_weight="5">
</RelativeLayout>
</LinearLayout>
<com.kripton.grapher.ui.CustomKeyboardView
android:id="@+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone"
/>
</RelativeLayout>
需要第一个相对布局,因为必须在其中放置KeyboardView。
然后我得到布局并在其中放置视图:
graphLayout = (RelativeLayout) rootView.findViewById(R.id.graph_layout);
functionLayout = (LinearLayout) rootView.findViewById(R.id.func_layout);
functionLayout.addView(addFunctionView);
graphLayout.addView(mainGraphView);
没有更多的布局操作。
addFunctionView 构造函数:
lp.width = LayoutParams.MATCH_PARENT;
lp.height = LayoutParams.WRAP_CONTENT;
lp.verticalMargin = 0.0f;
lp.horizontalMargin = 0.0f;
lp.gravity = Gravity.TOP;
this.setLayoutParams(lp);
graphView 构造函数:
lp.height = LayoutParams.MATCH_PARENT;
lp.width = LayoutParams.MATCH_PARENT;
this.setLayoutParams(lp);
this.setBackgroundColor(Color.WHITE);
getHolder().addCallback(this);
【问题讨论】:
-
提供执行渲染的代码将有助于解决问题。您是否在 Nexus 5 以外的任何其他设备上尝试过?
-
@ikust 刚刚添加了代码。是的,我也在一个人的 HTC 上试过,但不记得型号了。它也可以正常工作。
标签: android android-layout android-studio android-emulator android-linearlayout