手机和平板电脑上的Android设计问题

时间:2015-04-03 12:21:16

标签: android

我是Android新手,正致力于设计应用。我曾经为我的手机设备工作过,希望它能在平板电脑(Nexus 7)上运行。我使用视图寻呼机和框架来制作标签。但它在手机上工作正常,而不是平板电脑。 Design for Andriod Phone

Design for Android on Nexus 7

上面一个用于手机,下面一个用于平板电脑。请说明我做错了什么。

这是我的activity_main.xml文件: -

    <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivityNew"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar"/>

        <com.meroanswer.SlidingTabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="start|center"
            android:textAlignment="textStart"
            android:elevation="2dp"
            android:background="@color/primary"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:layout_weight="1">
            </android.support.v4.view.ViewPager>

    </LinearLayout>

    <!--<android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:background="#ffffff"
        android:scrollbars="vertical">

        </android.support.v7.widget.RecyclerView>-->

        <ListView
            android:layout_width="260dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@color/windowBackgroundColor"/>

</android.support.v4.widget.DrawerLayout>

这里的tab_subject.xml文件: -

<?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">

    <GridView
        android:id="@+id/gridView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:padding="4dp"
        android:clipToPadding="false"
        android:columnWidth="@dimen/item_width"
        android:numColumns="auto_fit"
        android:horizontalSpacing="4dp"
        android:verticalSpacing="4dp"
        android:stretchMode="columnWidth"/>

</RelativeLayout>

这是我的grid_items.xml文件: -

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:layout_height="2dp"
        android:layout_width="fill_parent"
        android:background="#88cdcdcd" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:orientation="horizontal"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:baselineAligned="false">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.3">

            <ImageView
                android:id="@+id/image"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:scaleType="centerCrop"
                android:layout_marginLeft="10dp"
                android:layout_gravity="center" />

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_weight="0.4"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:gravity="center">


                <TextView
                    android:id="@+id/subject_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Physics"
                    android:textSize="20dp"
                    android:textColor="@color/black_translucent"/>


                <TextView
                    android:id="@+id/chapters_completed"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="15dp"
                    android:text="50 chapters"/>



        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="0dp"
            android:layout_weight="0.3"
            android:layout_height="80dp"
            android:layout_gravity="right"
            android:gravity="center">

            <TextView
                android:id="@+id/progress_gained"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="30dp"
                android:textColor="@color/progressColor"
                android:padding="@dimen/spacing_large"
                android:layout_gravity="center" />

        </LinearLayout>
    </LinearLayout>

</FrameLayout>

activity_main.xml文件是主要活动布局,tab_subjects.xml是当前“模型检查”选项卡的布局文件。然后在gridview上添加grid_items.xml文件。

1 个答案:

答案 0 :(得分:0)

找到解决方案。这是因为我按照AndroidWeblineindia的建议在gridview上添加了固定宽度。