• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Dimensions of a fragments layout in android studio

  • Thread starter Thread starter Deleted User
  • Start date Start date
D

Deleted User

Guest
Hi,

Ok, I'll describe my situation briefly.

I have main_actvity.xml file which looks like this(just followed Android Devs guide):
Java:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ivan.fragmentsgameplay.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <fragment android:name="com.example.ivan.fragmentsgameplay.FragmentOne"
            android:id="@+id/list"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp" />
        <fragment android:name="com.example.ivan.fragmentsgameplay.FragmentTwo"
            android:id="@+id/viewer"
            android:layout_weight="2"
            android:layout_width="match_parent"
            android:layout_height="0dp" />
    </LinearLayout>
</RelativeLayout>



As you can see there are two fragments that are placed with 1/3 to 2/3 ratio one above the other.

The problem is when I work separately on, say: fragmentOne.xml file (via Design bar in Android Studio. )
It shows me that this layout actually fills up all the screen space.
So as far as can understand the final output layout will be dictated by main_activity.xml and all the great stuff that I would add to fragmentOne.xml will be resized in order to fit onto screen.

My question is about fragmentOne.xml (and fragmentTwo.xml too ^_^) is there some good way to define its dimensions so they initially suit those defined in main_activity.xml?

I mean in such case I'll work within a dimensions that will be actually presented to user, and will place all the elements(inside fragmentOne.xml file) in a proper way.

Without having a headache of rearranging those elements afterwards due to re-sizing of main_activity.xml.

An example of my fragmentOne.xml file:

Java:
<FrameLayout 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"
    tools:context="com.example.ivan.fragmentsgameplay.FragmentOne"
    android:background="#323b8a">

    <!-- TODO: Update blank fragment layout -->

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/frag_one_button"
        android:layout_gravity="center_horizontal|top"
        android:textAllCaps="true"
        android:text="Go To Fragment Two" />
</FrameLayout>


Thanks a lot for help. (hope my question was clear ^_^, and yes I'm an Android newbie)
 
Back
Top Bottom