android studio渲染和emulator上渲染的区别

android studio渲染和emulator上渲染的区别,android,android-layout,android-studio,android-emulator,android-linearlayout,Android,Android Layout,Android Studio,Android Emulator,Android Linearlayout,我的布局必须是这样的。这是android studio渲染。 但当我在模拟器上加载它时,我得到: 所有类型的仿真器都存在此问题。还测试了真正的Nexus5,效果不错。有什么问题吗 更新 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pa

我的布局必须是这样的。这是android studio渲染。

但当我在模拟器上加载它时,我得到:

所有类型的仿真器都存在此问题。还测试了真正的Nexus5,效果不错。有什么问题吗

更新

<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>
再也没有人操纵布局了

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);
    lp.height = LayoutParams.MATCH_PARENT;
    lp.width = LayoutParams.MATCH_PARENT;
    this.setLayoutParams(lp);
    this.setBackgroundColor(Color.WHITE);
    getHolder().addCallback(this);
graphView构造函数:

    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);
    lp.height = LayoutParams.MATCH_PARENT;
    lp.width = LayoutParams.MATCH_PARENT;
    this.setLayoutParams(lp);
    this.setBackgroundColor(Color.WHITE);
    getHolder().addCallback(this);

您是否使用Android Studio项目创建时生成的活动\u垂直\u边距活动\u水平\u边距的默认值

如果是这样,我认为从/main/res/values-w820dp文件夹中删除dimens.xml文件会有所帮助。该文件包含:


64dp

这在屏幕宽度超过820dp的设备上增加了额外的水平填充。由于某种原因,Android Studio preview忽略了这一点(我尝试选择Nexus 9设备进行预览)。

提供执行渲染的代码将有助于解决问题。除了Nexus 5之外,你有没有在其他设备上试用过它?@i刚刚添加了代码。是的,我也在一个人的HTC上试过,但不记得型号了。不,我不使用默认值。您在addFunctionView和graphView视图中实现了onMeasure()吗?如果这些视图中的onMeasure()没有以某种方式限制视图的宽度,我不确定还有什么可能导致问题。不,onMeasure()没有实现。我认为问题不在于代码,因为在真正的设备上,虽然它在Nexus5和htc的一款机型上运行良好。