【问题标题】:Android Design Issues on Phone and Tablet手机和平板电脑上的 Android 设计问题
【发布时间】:2015-04-03 12:21:16
【问题描述】:

我是 Android 新手,正在设计一款应用。我曾为我的手机设备工作,希望它也能在平板电脑(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 是当前模型考试选项卡的布局文件。然后grid_items.xml 文件稍后被添加到gridview 上。

【问题讨论】:

  • Roshan,发布您的 xml,您是否对宽度进行了硬编码?
  • 对于平板电脑版本,您可以使用 gridview,如果您在布局中使用了一些可能导致此问题的固定宽度/高度..
  • @GaurawYadav 添加了 xml 文件。
  • @Amsheer 添加了 ml 文件。
  • @AndroidWeblineindia 谢谢 .. 这是因为 gridview 有你建议的固定宽度。

标签: android


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多