I need a box within a box, with ~33% of empty room at the top of the first box, and then another box below that. I need it to be centered. I would like this to essentially fill_parent on a mobile phone, but on a tablet (the primary device for this app), it should remain the same size but be centered in the middle of the screen. How can I do this?
I’m including to examples since it’s a little hard for me to explain.
Mobile
|---------------------------|
| ~33% Blank space |
| |
| |---------------------| |
| | | |
| | | |
| | Login Box | |
| | Password | |
| | | |
| | | |
| | | |
| | | |
| | | |
| |---------------------| |
|---------------------------|
Tablet
|---------------------------------------|
| ~33% Blank space |
| |
| |---------------------| |
| | | |
| | | |
| | Login Box | |
| | Password | |
| | | |
| | | |
| | | |
| | | |
| | | |
| |---------------------| |
|---------------------------------------|
Edit Here is the XML I currently have. I’m not getting intellisense for anything, (I usually get suggestions), and I’m getting a cast exception with multiple layouts. Is there something wrong with the XML?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
>
<LinearLayout android:id="@+id/topSpacer"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".33"
android:orientation="horizontal"
></LinearLayout>
<LinearLayout
android:id="@+id/bottomSection"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".67"
android:orientation="horizontal"
>
<LinearLayout
android:id="@+id/loginSection"
android:layout_width="320dip"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
<TextView
android:text=""
android:id="@+id/errorMessage"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<TextView
android:text="Please login using your active directory credentials."
android:id="@+id/loginMessage"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<AutoCompleteTextView
android:id="@+id/loginUsername"
android:text="Username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/loginPassword"
android:text="Password"
android:password="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/loginButton"
android:text="Login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="results"
android:id="@+id/resultsMessage"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Try a combination of linear layouts that utilize the
weightSumproperty. Also notice that the inner box’s width is fixed as you mentioned on the tablet you don’t want it to re-size.Try this:
*EDIT: i used a relative layout to get the inner box centered *