0

我正在尝试为平板设备设计类似的东西

-640x480 区域(左边界)--------灵活的空宽度--------控制区域(右边界)-

灵活的宽度取决于平板电脑的大小。滚动窗格仅用于在移动设备上进行调试。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView11"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <HorizontalScrollView
        android:id="@+id/scrollView12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/ll1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#24476D" >

            <view
                android:id="@+id/dmi"
                android:layout_width="640dp"
                android:layout_height="480dp"
                android:layout_gravity="left"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="20dp"
                android:layout_weight="1"
                class="com.example.ecorailnet.DMIView"
                android:background="#8fc7ff" />

            <TextView
                android:id="@+id/empty_list_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="List view is empty"
                android:visibility="gone" />

            <view
                android:id="@+id/cpp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:layout_weight="1"
                class="com.example.ecorailnet.ControlPanel" />
        </LinearLayout>
    </HorizontalScrollView>
</ScrollView>

最后是现在的情况以及它应该是什么样子。

现在

提前致谢

问候

4

2 回答 2

1

如果您只想要左边的东西和右边的东西,请使用RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#24476D" >

    <view
        android:id="@+id/dmi"
        android:layout_width="640dp"
        android:layout_height="480dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_gravity="left"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="20dp"
        class="com.example.ecorailnet.DMIView"
        android:background="#8fc7ff" />

    <view
        android:id="@+id/cpp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_gravity="right"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        class="com.example.ecorailnet.ControlPanel" />

</RelativeLayout>

你能得到的唯一问题是整个东西不适合小屏幕。在这种情况下,两个视图将重叠。

于 2012-08-14T15:29:34.033 回答
0

如果你真的确定你想要一个 640x480 像素的 DMIView。

您可以尝试覆盖 DMIView 的 onMeasureMethod

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    this.setMeasuredDimension(640,480);
}

或者如果你想要一个占据所有高度的右缩放 DMIView

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
    this.setMeasuredDimension(Math.round(parentHeight * 640 / 480f),parentHeight);      
}

希望这些会有所帮助。

于 2012-08-14T16:15:28.463 回答