How can i made the layout that will work in both T

2019-01-15 03:37发布

I made the layout from xml with on tablet layout of emulator size. But when open on same layout on android phone device then every thing distorted, So can i make a xml layout that will work fine in both of device phone and tablet also. Please suggest me, appreciate your answer.

3条回答
迷人小祖宗
2楼-- · 2019-01-15 03:53

Use Tables and weights to create the same or similar aspect ratio on a phone that would be on a tablet. I would only create different Layouts as a last resort.

<TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight=".33" >
             //Note: You will need some other TableRows fill in the difference of this Table Row..2 more of the same will equal 1.
        <TextView
            android:id="@+id/x"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="3dp"
            android:layout_weight=".33"
            android:background="@drawable/buttonx"
            android:gravity="center"
            android:text="Words"
            android:textColor="#ffffff"
            android:textSize="16sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/x2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="3dp"
            android:layout_weight=".33"
            android:background="@drawable/buttonx2"
            android:gravity="center"
            android:text="Other Words"
            android:textColor="#ffffff"
            android:textSize="16sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/x3"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="3dp"
            android:layout_weight=".33"
            android:background="@drawable/buttonx3"
            android:gravity="center"
            android:text="More Words"
            android:textColor="#ffffff"
            android:textSize="16sp"
            android:textStyle="bold" />

    </TableRow>
查看更多
小情绪 Triste *
3楼-- · 2019-01-15 03:57

Make your resource like this.

res/layout/my_layout.xml // layout for normal screen size ("default")

res/layout-small/my_layout.xml // layout for small screen size

res/layout-large/my_layout.xml // layout for large screen size

res/layout-xlarge/my_layout.xml // layout for extra large screen size

res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

res/drawable-mdpi/my_icon.png // bitmap for medium density

res/drawable-hdpi/my_icon.png // bitmap for high density

res/drawable-xhdpi/my_icon.png // bitmap for extra high density

For more reference. reference1.

Add this in your manifest.xml

<supports-screens
            android:smallScreens="true"
            android:normalScreens="true"
            android:largeScreens= "true"
            android:anyDensity="true"
    />

Hope this will help you.

查看更多
一夜七次
4楼-- · 2019-01-15 04:01

You can create two seperate layout for your phone and Tab. What you need to do is create a layout file with "filename" for phone and for tab create a layout file by right clicking project and selecting new>android xml layout file> and then type a "filename", click next and select Size from the right pane and select x-large from drop down list. Your layout file for tab is created separately so customise your layout seperately.

查看更多
登录 后发表回答