问题
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.

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
回答1:
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
回答2:
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>
回答3:
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.
回答4:
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
来源:https://stackoverflow.com/questions/17440665/android-layout-correct-alignment