I need the following thing:
3 layouts:
Header
Content
Footer
Header must be on the top footer must be sticked to the bottom (android:layout_alignParentBottom="true").
But how to make middle to occupy the whole other screen? Thanks.
Here is my solution (with android:layout_weight and ScrollView):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Header"
tools:ignore="HardcodedText" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Content"
tools:ignore="HardcodedText" />
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Footer"
tools:ignore="HardcodedText" />
</LinearLayout></LinearLayout>
And the result picture :
Hi Use the following lines
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Button" >
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Header" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/linearfooter"
android:layout_below="#+id/button1"
android:background="#android:color/darker_gray"
>
</LinearLayout>
<LinearLayout
android:id="#+id/linearfooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" >
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="footer" />
</LinearLayout>
</RelativeLayout>
hope this helps you.
Use a height of 0dp and
android:layout_weight
set to 1
Finally I've got the next solution:
To the middle layout I added:
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header"
android:layout_weight="1">
And it works!
Related
i have an app which has a main RelativeLayout and some LinearLayout within it.
My problem is that the LinearLayout doesn't fit to the full lenght of the screen:
this is my xml file :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/bgApp" >
<LinearLayout
android:id="#+id/mainView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="#dimen/topBarHeight"
android:background="#drawable/top"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="#android:color/transparent" >
<ImageView
android:id="#+id/scoreLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/coin_icon"
android:contentDescription="#string/app_name"/>
<TextView
android:id="#+id/mainScreenTotalPoints"
style="#style/pointTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/btnPaddingV"
android:text="#string/startPoint"
android:textSize="#dimen/buttonTextSize" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/logPadding"
android:text="#string/app_name"
android:textColor="#d0105e"
android:textSize="27sp"
android:textStyle="bold"/>
<LinearLayout
android:id="#+id/root"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="#dimen/btnPadding"
android:paddingRight="#dimen/btnPadding" >
<Button
android:id="#+id/play"
android:layout_width="fill_parent"
android:layout_height="#dimen/buttonHeight"
android:background="#drawable/button_blue"
android:gravity="center"
android:onClick="onButtonClickPlay"
android:text="#string/play"
android:textColor="#color/btnMain"
android:textSize="#dimen/buttonTextSize" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:orientation="vertical"
android:paddingTop="#dimen/mainbox" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/btnPadding" >
<Button
android:id="#+id/btn_how"
style="#style/btnCapital"
android:layout_width="fill_parent"
android:layout_height="#dimen/buttonHeight"
android:layout_marginRight="#dimen/btnPaddingV"
android:layout_weight="1.0"
android:background="#drawable/button_green_how"
android:onClick="onButtonClickHowToPlay"
android:text="#string/howInfo" />
<Button
android:id="#+id/btn_rate"
style="#style/btnCapital"
android:layout_width="fill_parent"
android:layout_height="#dimen/buttonHeight"
android:layout_marginLeft="#dimen/btnPaddingV"
android:layout_weight="1.0"
android:background="#drawable/button_rate"
android:onClick="onButtonClickRate"
android:text="#string/rateInfo" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/btnPadding" >
<Button
android:id="#+id/sound"
style="#style/btnCapital"
android:layout_width="0dp"
android:layout_height="#dimen/buttonHeight"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="#drawable/mute_01"
android:gravity="center"
android:onClick="onButtonClickSound"
android:text="#string/mute" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/btnPadding" >
<Button
android:id="#+id/moreapp"
style="#style/btnCapital"
android:layout_width="0dp"
android:layout_height="#dimen/buttonHeight"
android:layout_marginTop="1.0dip"
android:layout_weight="1.0"
android:background="#drawable/button_blue"
android:gravity="center"
android:onClick="onButtonClickMoreApp"
android:text="#string/moreapp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:gravity="center"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
ads:adSize="BANNER"
ads:adUnitId="#string/admob_publisher_id"
android:gravity="bottom" />
</LinearLayout>
</LinearLayout>
</ScrollView>
here is a screenshot :
Screenshot after running app
and here a screenshot of layout before running app:
Screenshot before running app
Thank you in advance !
You need to use the ScrollView attribute called android:fillViewport="true". This attribute causes the scroll view’s child to expand to the height of the ScrollView if needed.
When the child is taller than the ScrollView, the attribute has no effect.
Check out this for detail explanation.
You have to use attribute android:fillViewport="true".in your scrollview.
This is my layout of the scrollView. It just scrolls infinitely. I need the scroll just for the elements that the user sees in the activity. I have tried all my efforts to it however, it didnt work out. Heres the layout..
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/parentLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginLeft="-20dp"
android:layout_marginStart="-20dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</Button>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="100dp"
android:layout_marginStart="100dp"
android:gravity="center"
android:text="Create event" >
</Button>
</LinearLayout>
Set the height of the LinearLayout (id parentLayout) to wrap_content.
The ScrollView is set to wrap_content, but its child is set to fill_parent. This makes no sense, as something needs to provide a size.
I am trying to build a little Android App and I need two LinearLayout side by side. (50/50)
How it looks:
http://i.stack.imgur.com/C9yCF.png
I already try to use: android:layout_width="0dp" android:layout_weight="1" but it didn't work.
This is my XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/part">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="9pt"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:baselineAligned="true"
android:background="#ff7f7f7f"
android:id="#+id/head">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="123456789"
android:id="#+id/textView"
android:paddingStart="3pt"
android:paddingLeft="3pt"
android:textColor="#ffffffff"
android:singleLine="false" />
</LinearLayout>
<LinearLayout
android:id="#+id/left"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_below="#+id/head"
android:background="#ffff0100" >
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/head"
android:background="#fffcff00" />
How it should look:
http://i.stack.imgur.com/tup01.png
Have one more LinearLayout with horizontal orientation below your #+id/head LinearLayout.
Set its width to match_parent. Keep the last two LinearLayouts inside the new LinearLayout and have android:layout_weight=0.5 for both. Something like:
<RelativeLayout>
<LinearLayout> </LinearLayout>
<LinearLayout
...
android:orientation:"horizontal"/>
<LinearLayout
android:weight="0.5"
android:width="0dp"
... />
</LinearLayout>
<LinearLayout
android:weight="0.5"
android:width="0dp"
... />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
You can't use layout_weight with RelativeLayouts children. Put/Wrap both LinearLayouts in another LinearLayout.
Hey try this code...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/part"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/head"
android:layout_width="fill_parent"
android:layout_height="9pt"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#ff7f7f7f"
android:baselineAligned="true"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3pt"
android:paddingStart="3pt"
android:singleLine="false"
android:text="123456789"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/head"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/left"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff0100"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#fffcff00"
android:orientation="vertical" />
</LinearLayout>
The android layout lacks proportion when I set the background of Imagebutton.
And the code of xml is like the following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/player_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/buttonLayout" >
<FrameLayout
android:id="#+id/player_surface_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
<SurfaceView
android:id="#+id/player_surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/findCameraButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:text="#string/label_find_camera" />
<Button
android:id="#+id/SettingButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:text="#string/Camera_WiFi_setup" />
<ImageButton
android:id="#+id/FileSavebutton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:background="#drawable/save_in_camera" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TimeStampLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text=""
android:textColor="#ffff00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/snapshotButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="#string/label_app_snapshot" />
<Button
android:id="#+id/recordButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="#string/label_app_record" />
<ImageButton
android:id="#+id/photo_record_mode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:background="#drawable/turn_to_photomode"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
How to setup can make the top of LinearLayout no deformation like the LinearLayout of bottom ?
Have you tried changing all the android:layout_height values from match_parent to wrap_content?
i think you should use scaleType to get your image look nice
prefer fitXY
like that
android:scaleType="fitXY"
put inside your xml to be whole code like that
<ImageButton
android:id="#+id/photo_record_mode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:background="#drawable/turn_to_photomode"
android:scaleType="fitXY"/>
I have a layout like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e4e8ed"
android:gravity="top" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/app"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0px"
android:orientation="vertical"
android:padding="0px" >
<include
android:id="#+id/tabBar"
layout="#layout/tab" />
<Button
android:id="#+id/nist"
android:layout_width="match_parent"
android:layout_height="67dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="3dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:background="#drawable/ready"
android:textColor="#FFFFFF" />
<ListView
android:id="#+id/lastCases"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2.08"
android:longClickable="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="7dp"
android:layout_below="#id/app"
android:background="#drawable/dropshadow_custom" >
<TextView
android:id="#+id/error"
style="#style/AudioFileInfoOverlayText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="120dp"
android:gravity="center"
android:text="No Cases"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#D6D8D9"
android:textSize="40dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/app"
android:background="#000000"
android:gravity="bottom"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
I try to align the last LinearLayout on top of the layout which holds the ListView by using this tag: android:layout_alignTop="#+id/app" But it doesn't seem to work. How can accomplish this?
Many Thanks!
Without any content a Layout with layout_width="wrap_content" and layout_height="wrap_content" is not shown as its width and height have a value of 0! Even if you have set some background color nothing will appear! You either have to add some content to the layout or you have to define another layout dimension. The position of your layout with android:layout_alignTop="#+id/app" should be correct. Hope that helps.
You can set "layout_below" on the first layout targeting to the last layout.
The code is that, I put a button inside the top layout as an exemple (Obs: In your listview you should use 0dp in layout_weight cause you already use layout_weight ^^) :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e4e8ed"
android:gravity="top" >
<LinearLayout
android:id="#+id/app"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0px"
android:orientation="vertical"
android:layout_below="#+id/top"
android:padding="0px" >
<Button
android:id="#+id/nist"
android:layout_width="match_parent"
android:layout_height="67dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="3dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:textColor="#FFFFFF" />
<ListView
android:id="#+id/lastCases"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.08"
android:longClickable="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="7dp"
android:layout_below="#+id/app" >
<TextView
android:id="#+id/error"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="120dp"
android:gravity="center"
android:text="No Cases"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#D6D8D9"
android:textSize="40dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#000000"
android:gravity="bottom"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Top"
/>