0

I am working on a project and I have run into some problems. I haven't worked with the layouts very much so I don't know if this is possible or not.

In the picture I have added the project mock-up. For the lower screen resolution it looks fine, but when I put the app on 5 inch device, this orange area is too high and I wanted to know if it is possible somehow to get that area centered.

enter image description here

The orange area is a LinearLayout and everything is wrapped inside LinearLayout. Hope you understand what I mean I what I am asking.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffff0000"
    android:orientation="vertical"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >

    <LinearLayout
        android:id="@+id/first"
        android:layout_width="match_parent"
        android:layout_height="76dp"
        android:background="#175797"
        android:orientation="vertical" >

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Subject" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/second"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#00FFFF"
        android:orientation="vertical" >

        <Button
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="Send" />
    </LinearLayout>

    <LinearLayout
        android:layout_gravity="bottom"
        android:id="@+id/third"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="#FFA500"
        android:orientation="horizontal" >
    </LinearLayout>

</LinearLayout>

This is code for the mock-up. For the project it's pretty much the same

Karlis
  • 1,501
  • 4
  • 19
  • 31

4 Answers4

1

Try this !

I tried putting Linear layout inside a relative layout and defining its gravity. I checked it on various resolution.Give it a try

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff0000"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp" >

<LinearLayout
    android:id="@+id/first"
    android:layout_width="match_parent"
    android:layout_height="76dp"
    android:background="#175797"
    android:orientation="vertical" >

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Subject" />
</LinearLayout>

<LinearLayout
    android:id="@+id/second"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:background="#00FFFF"
    android:orientation="vertical" >

    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="Send" />
</LinearLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    >

    <LinearLayout
        android:id="@+id/third"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="#FFA500"
        android:gravity="center"
        android:orientation="horizontal" >
    </LinearLayout>
</RelativeLayout>

baloo
  • 217
  • 1
  • 8
0

May be try android:layout_gravity="center" that should do the trick :) Also in addition, you can add android:layout_centerInParent="true" and take a look at this thread as well.

g00dy
  • 6,752
  • 2
  • 30
  • 43
0

you can try @g00dy answer or else

You have to create separate layout for phablet (i.e. 5 inch devices)

Here in this link they had explain how we can put our tablets layouts...

On android developer site they have had explain how android manage layouts for different screen sizes check this link

Community
  • 1
  • 1
Gru
  • 2,686
  • 21
  • 29
0

for giving the compatibility of xml for all android devices and tablets, please use the Relative Layout as a parent view and set the component according to your requirement. please follow this link for more reference: http://developer.android.com/reference/android/widget/RelativeLayout.html

Karan Maru
  • 991
  • 6
  • 17