I`m trying to create the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
<SeekBar
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TextView>
</LinearLayout>
I`d like to give the 80% of the parent layout to the textView1 and textView2, wrap the SeekBar as much as possible and the rest of the free space give to the textView3.
I`ve tried to:
use layout_weight attributes (respectively - 4, 4, 1, 1) but the last
view overlaps the SeekBar
use layout-weight only with textView1 and textView2, set SeekBar`s height to "wrap_content" and set "match_parent" for the last view
And now I have no more ideas. Have you ever had such a problem?
well to create this layout I would try :
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4" >
</TextView>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4" >
</TextView>
<SeekBar
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
</TextView>
make change on weights tu adjust sizes.
let the seek bar to wrap content, give weight on other views.
tell me if that helps.
Related
I have movies Application
and I am working in the details of the movie layout
now I have two posters for each movie (orginal poster and backdrop poster)
I am working to make some thing like this:
I am trying to do that but I have problem which is: the backdrop poster came to the front of orginal poster and hide it (backdrop poster hide the orginal poster)
how I can send the original poster to the front of backdrop poster
this is my code:
<?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:background="#ffffff"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<ImageView
android:id="#+id/iv_movie_poster1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="67dp"
android:src="#drawable/ic_launcher_background" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="#+id/relativeLayout2"
>
<ImageView
android:id="#+id/iv_movie_poster_back"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher_background" />
<!--android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"-->
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/iv_movie_poster1"
android:layout_centerHorizontal="true"
android:background="#ffff"
android:elevation="4dp"
android:orientation="vertical"
android:padding="8dp"
android:id="#+id/relativeLayout2">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="30dp">
<TextView
android:id="#+id/tv_movie_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#57486c"
android:padding="16dp"
android:textSize="36sp"
tools:text="The Hunger Games" />
<TextView
android:id="#+id/tv_movie_lang"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="italic"
tools:text="English" />
<TextView
android:id="#+id/tv_movie_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="7.4/10" />
<TextView
android:id="#+id/tv_movie_year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
tools:text="2015"
/>
<TextView
android:id="#+id/tv_movie_overview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
tools:text="Katniss Everdeen and Peeta Mellark become targets of the Capitol after their victory in the 74th Hunger Games sparks a rebellion in the Districts of Panem. " />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
and thankyou
Made the layout i think it will fulfill your requirement. Using Frame Layout overlay the poster image on the back image and accordingly manage.
Follow this XML part for upper layer. Make changes accordingly relate to images you used.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<LinearLayout
android:id="#+id/llMain"
android:layout_width="match_parent"
android:layout_height="280dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<ImageView
android:id="#+id/iv_movie_poster1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/testimage" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal">
<ImageView
android:id="#+id/iv_movie_poster_back"
android:layout_width="150dp"
android:layout_height="150dp"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/com_facebook_button_icon_blue" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
Here you can view the upper layer output.
I just can't seem to find a way to fit the photo onto my home page screen, I've tried many different ways but it wasn't successful. I have an image that pushes the layout that is under it and squeezes the buttons on the screen. Is there any way I can auto resize the height it for different screens? I only need the height since the width should be match_parent. Below is the xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical"
>
<RelativeLayout
android:id="#+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#drawable/nav_bar_homepage" >
<TextView
android:id="#+id/pageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="WELCOME!" />
<ImageView
android:id="#+id/hiddenIcDrawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:src="#drawable/nav_icon"
android:visibility="invisible" />
</RelativeLayout>
<ImageView
android:id="#+id/horLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/headerLayout"
android:scaleType="center"
android:src="#drawable/line_big_white" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:scaleType="fitStart" >
<ImageView
android:id="#+id/image_homepage_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center_horizontal"
android:src="#drawable/image_homepage"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/field_red_homepage"
android:orientation="vertical"
android:scaleType="fitXY" >
<ImageView
android:id="#+id/logo_homep"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:paddingBottom="10dp"
android:scaleType="fitXY"
android:src="#drawable/logo_homepage" />
<ImageView
android:id="#+id/redeembytton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/btn_redeemrewards"
android:scaleType="fitXY" >
</ImageView>
<ImageView
android:id="#+id/orderbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/btn_orderonline"
android:scaleType="fitXY" >
</ImageView>
<ImageView
android:id="#+id/rewardsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/btn_earnrewards"
android:scaleType="fitXY" >
</ImageView>
<ImageView
android:id="#+id/referFriendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/btn_referafriend"
android:scaleType="fitXY" >
</ImageView>
</LinearLayout>
</LinearLayout>
Wrap you xml code into ScrollView if you are okay with scrolling down to reach your contents under ImageView. If you don't want to scroll down, it is best to use "weight" attribute. I am giving you an idea how to implement it in your code.
Let's say the height of the whole screen is 1. You have an image and a button to put on the screen for all devices. So split the screen into two parts... 0.8 for imageview and 0.2 for the button. You can use the code below to get this result.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp" <!-- Important >
android:orientation="vertical"
android:layout_weight=".8" > <!-- 80% of your screen size>
<!-- Your ImageView >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp" <!-- Important >
android:orientation="vertical"
android:layout_weight=".2" > <!-- 20% of your screen size>
<!-- Your Button >
</LinearLayout>
</LinearLayout>
Try this
I think you should use
android:layout-weight="1" for adjusting the height according to different devices.use it in your <ImageLayout/>.
I am struggling big time with trying to make a simple layout with two TextView:s under each other on the left and corresponding two TimePicker:s under each other on the right. However, whichever view I use or attributes I choose that seem relevant I do not get the desired outcome. Here is my current try:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
>
<TextView
android:layout_column="1"
android:id="#+id/text_start_time"
android:text="#string/start_time"
android:gravity="center_horizontal"
/>
<TimePicker
android:id="#+id/time_picker_start"
android:timePickerMode="spinner"
android:layout_marginTop="-25dp"
android:layout_marginBottom="-25dp"
android:layout_gravity="center"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
>
<TextView
android:layout_column="1"
android:id="#+id/text_end_time"
android:text="#string/end_time"
android:layout_gravity="center_horizontal"
/>
<TimePicker
android:id="#+id/time_picker_end"
android:timePickerMode="spinner"
android:layout_marginTop="-25dp"
android:layout_marginBottom="-25dp"
/>
</TableRow>
<TableRow>
<Button
android:layout_column="2"
android:layout_width="match_parent"
android:text="#string/button_calculate"
android:gravity="center"
android:onClick="calculateWorkingTime"
/>
</TableRow>
</TableLayout>
This gives the following output
Where is "Start"?
As you can see "Start" is not even shown! I would like to align "Start" with the vertical center of the TimePicker spinner. How to do that?
First, don't use a TableLayout. Use Linears, as you are a beginner and they're easier to use and understand. Here's what you should do:
<?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" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/text_start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start_time"
android:gravity="center_horizontal"
/>
<TimePicker
android:id="#+id/time_picker_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner"
android:layout_marginTop="-25dp"
android:layout_marginBottom="-25dp"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/text_end_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/end_time"
android:gravity="center_horizontal"
/>
<TimePicker
android:id="#+id/time_picker_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner"
android:layout_marginTop="-25dp"
android:layout_marginBottom="-25dp"
android:layout_gravity="center"
/>
</LinearLayout>
<Button
android:layout_column="2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="#string/button_calculate"
android:gravity="center"
android:onClick="calculateWorkingTime"
/>
</LinearLayout>
What I've done is creating a Linear Layout and, into it, another two with orientation:horizontal, which makes the elements appear one next to each other.
Also, I've put width and height to all the elements, what is very important.
I've put wrap_content, if you want to change it, no problem.
I didn't test it, if there's any error, just coment
Hope it helps!
So here is the basic layout I'm after: http://i.imgur.com/Y5rHEpc.jpg
In the designer, I can't get the rectangle left-aligned how I want it. Everything just overlaps. http://i.imgur.com/ufWmVgR.png
What would be the best way to lay this out? I'm new and having a really tough time figuring out these layouts. I'm using an extremely simple rectangle shape that I created in my drawables folder.
Any tips appreciated.. I'm really banging my head against the wall here.
<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:padding="5dp"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/row_rectimage"
android:layout_width="44dp"
android:layout_height="match_parent"
android:src="#drawable/rectangle" />
<TextView
android:id="#+id/row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Some Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/row_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/row_title"
android:layout_marginTop="5dp"
android:text="Some Description"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16sp" />
.....
This adds another nested LinearLayout but the performance loss should be negligible.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="#+id/row_rectimage"
android:layout_width="44dp"
android:layout_height="match_parent"
android:src="#drawable/rectangle" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="5dp" >
<TextView
android:id="#+id/row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Some Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/row_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/row_title"
android:layout_marginTop="5dp"
android:text="Some Description"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
I want to create layout similar to one attached. The left hand side needs to be scrolled text occupying 75% of screen horizontally. The remaining 25% will consists of few icons stacked vertically and a button that should align at the bottom.
But I can't seem to get the working.
http://i.imgur.com/TzzBy9h.png
I would appreicate any help in getting this layout stuff right, my current layout looks like this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/card_details"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="50"
android:layout_weight="0.7"
android:gravity="bottom"
android:text="" >
</TextView>
<ImageView
android:id="#+id/photo_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:minHeight="84dp"
android:minWidth="84dp"
android:scaleType="centerCrop" />
</LinearLayout>
</ScrollView>
<LinearLayout android:gravity="center" android:orientation="horizontal"
android:padding="4.0dip" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/read_id_btn"
style="#style/PageButton"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="#string/read_id" />
</LinearLayout>
</LinearLayout>
~
Try weigth "2" and "1".
Good luck with it.
Try This code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="15dp"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>