I'm new to Android dev so sorry for what is probably a basic question....
I'm trying to get 2 textviews to appear at the top of the screen and take up an equal amount of space each BUT to have a margin of say 20dp between the 2 views and on the left and the right hand side of the screen.
Much like
My code currently is:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A1887F"
android:orientation="horizontal">
<TextView
android:id ="#+id/1_Heading"
android:text="1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp" />
<TextView
android:id ="#+id/2_Heading"
android:text="2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
</LinearLayout>
Any ideas and sorry if this is a basic question - I've tried to find a solution online but nothing much helps.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A1887F"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id ="#+id/1_Heading"
android:text="1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
<TextView
android:id ="#+id/2_Heading"
android:text="2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
</LinearLayout>
You just need to give half right margin to your first Textview and half left margin to your second Textview as below:-
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A1887F"
android:orientation="horizontal">
<TextView
android:id ="#+id/1_Heading"
android:text="1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp" />
<TextView
android:id ="#+id/2_Heading"
android:text="2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
</LinearLayout>
you can handle this with giving a 20dp padding to parent (LinearLayout) and then 10dp margin from end to the first button, and 10dp margint from start to the second button.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A1887F"
android:padding="20dp"
android:orientation="horizontal">
<TextView
android:text="1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginEnd="10dp"
/>
<TextView
android:text="2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginStart="10dp"
/>
Try with this layout xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A1887F"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/heading1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#4CAF50"
android:padding="5dp"
android:text="1"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#ffffff" />
<TextView
android:id="#+id/heading2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#4CAF50"
android:padding="5dp"
android:text="2"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
Try this one :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A1887F"
android:layout_weight="100"
android:orientation="horizontal">
<TextView
android:id ="#+id/Heading_1"
android:text="1"
android:layout_width="0dp"
android:layout_weight="50"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
<TextView
android:id ="#+id/Heading_2"
android:text="2"
android:layout_width="0dp"
android:layout_weight="50"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceMedium"
android:background="#4CAF50"
android:padding="10dp"
android:textColor="#ffffff"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
</LinearLayout>
Results :
Give android:layout_marginEnd="10dp"on the First TextView
Give android:layout_marginStart="10dp"on the Second TextView
Was Able to achieve this using below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A1887F"
android:orientation="horizontal">
<TextView
android:id="#+id/btn1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:padding="10dp"
android:background="#4CAF50"
android:text="1"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#ffffff" />
<TextView
android:id="#+id/btn2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:padding="10dp"
android:background="#4CAF50"
android:text="2"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
Related
Fragment with scrollview
Hi guys. Here is my current design. Linear layout with scroll view on left side with buttons keeps on expanding depending how many buttons i put. What i'm trying to do is it keep it fix size and let the scroll view do it work. I keep on changing the minWidth and minHeigth and even the layout_width and layout_height in fix size but it still keeps on expanding. Any idea what im doing wrong?.Thanks
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="800dp"
android:minHeight="600dp"
android:weightSum="100">
<!--Top Title Bar-->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:weightSum="100"
android:background="#drawable/AppBarBackground">
<TextView
android:id="#+id/tvCompanyName"
android:fontFamily="#string/fontFamily"
android:text="Reports"
android:textColor="#color/white"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="15"
android:gravity="center|left"
android:textSize="#dimen/textSizeSmall"
android:textStyle="bold"
android:paddingLeft="20dp"
android:paddingRight="10dp" />
</LinearLayout>
<!--Content Layout-->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="85"
android:weightSum="100">
<!--Buttons Left Size-->
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:fillViewport="false">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/BackgroundWhite">
<Button
android:id="#+id/btnXReadRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="X-Read"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnZReadRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Z-Read"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnSalesRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Sales"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnDiscountRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Discount"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnItemVoidRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Item Void"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnTransVoidRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Transaction Void"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnZReadRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Z-Read"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnSalesRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Sales"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnDiscountRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Discount"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnItemVoidRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Item Void"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
<Button
android:id="#+id/btnTransVoidRpt"
android:textAllCaps="false"
android:fontFamily="#string/fontFamily"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#drawable/ButtonSelectorBorderBaseColor"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textColor="#color/blue"
android:text="Transaction Void"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_weight="5" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="70"
android:weightSum="100"
android:background="#drawable/BackgroundWhite" />
</LinearLayout>
</LinearLayout>
What i'm trying to do is it keep it fix size and let the scroll view do it work.
Try to set a fixed size to ScrollView instead of using match_parent.
For example:
<ScrollView
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="30"
android:fillViewport="false">
...
</ScrollView>
And the result is:
If you want your layout to be fixed sized You need to set your height width fixed
i.e.
android:layout_width="YOUR WIDTH"
android:layout_height="YOUR_HEIGHT"
[SOLVED] Marked the working solution. #GIBIN THOMAS: this suggestion works as well (similar).
Below I've posted an issue which arise when the Scoring increases, making it to expand and therefor push the other TextView out of the screen. I've tried changing the Width and height in all kinds of ways for both the TextViews themselves and the Layout that's wrapping them, without any luck.
PROBLEM: Anyone got a good solution how to set my Layout and/or TextViews width and height to prevent the Scoring TextView from pushing the Lives TextView out of the screen?
.
This is my XML-file:
The layout & textviews below are all inside another layout (including 4 buttons, one imageview and another textView - excluded in the code)
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="#string/current_score"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/current_score_0"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="205dp"
android:layout_marginStart="205dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="#+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="#string/lives"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lives_5"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Try this layout:
use android:weightSum and android:layout_weight properly
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="left"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="SCORE"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCORE"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="#+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="Lives"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lives"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Output:
This will fix your issue
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="Current Score"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Scrore"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="Lives"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lives 5"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Please remove the strings i have added also if you have further doubts feel free to note down below
Please make sure to apply proper weight and other changes as follows :
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:padding="10dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:orientation="horizontal">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="current_score"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:text="current_score_0"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="#+id/lives"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:gravity="center"
android:text="lives"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentLivesEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lives_5"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Just give the LinearLayout , layout_weight="5" .. Like
android:layout_weight="3" and make the android:layout_width = "0px"
Note="Set the layout weight according to your spacing" ...
The Linear Layout in which u have fitted these two textviews
Simply replace your current score linear layout with this relative layout and you are done.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/currentScoreText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_alignParentLeft="true"
android:text="current_score"
android:textColor="#android:color/black"
android:textSize="20sp" />
<TextView
android:id="#+id/currentScoreEasy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="current_score_0"
android:textColor="#android:color/holo_red_dark"
android:textSize="20sp" />
</RelativeLayout>
I have my views in a scroll view so that if the content is bigger than the screen size, the user can scroll down. I have noticed a weird thing.
The first time the content comes up, it doesn't scroll. However, when the user changes a setting and the content of the views which are inside the scroll view reloads it does become scrollable.
Why is this? Is it clear what I mean?
EDIT: This only happens on my Nexus 5X. But when I used a Samsung J10 it works right away.
My XML is a relative layout, with a child element of the scroll view, which contains other views.
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.apps.reuven.egertandcohentravel.Activities.HomeActivity"
tools:showIn="#layout/activity_home">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="50dp"
android:id="#+id/progressBar"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:visibility="gone"
/>
<TextView
android:id="#+id/textViewLinkToOrder"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here to book travel insurance."
android:textColor="#color/colorPrimary"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:gravity="center"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/buttons_linear_layout"
android:orientation="horizontal"
android:layout_below="#id/textViewLinkToOrder">
<Button
android:layout_width="200dp"
android:id="#+id/choose_country_button"
android:onClick="onChooseCountryButtonClick"
android:layout_height="wrap_content"
android:text="Choose country"
android:layout_marginLeft="5dp"
android:background="#color/colorPrimary"
android:layout_weight="1"
android:textColor="#ffff"
android:layout_marginRight="5dp"
android:layout_below="#id/textViewLinkToOrder"
android:layout_centerHorizontal="true"/>
<Button
android:layout_width="200dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:textColor="#fff"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="#+id/automatic_country_button"
android:layout_height="wrap_content"
android:text="My Location"
android:layout_below="#id/choose_country_button"
android:layout_centerHorizontal="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayoutAllDetails"
android:layout_below="#id/buttons_linear_layout"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No country yet selected"
android:gravity="center"
android:id="#+id/textView_coumtry_name"
android:textColor="#000000"
android:textSize="30sp"
android:padding="5dp"
android:textStyle="bold"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/police"/>
<TextView
android:textSize="17sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Police"
android:textColor="#000000"
android:layout_gravity="center_vertical" />
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/police_text_view"
android:text=""
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:id="#+id/police_phone_button"
android:layout_width="30dp"
android:layout_gravity="center_vertical"
android:layout_height="30dp"
android:src="#android:drawable/sym_action_call"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ambulance"/>
<TextView
android:textSize="17sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ambulance"
android:textColor="#000000"
android:layout_gravity="center_vertical" />
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ambulance_text_view"
android:text=""
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:layout_width="30dp"
android:layout_gravity="center_vertical"
android:layout_height="30dp"
android:src="#android:drawable/sym_action_call"
android:id="#+id/ambulance_phone_button"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/israel_consulate"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:textSize="17sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Israel Consulate"
android:textColor="#000000"
android:layout_gravity="center_vertical" />
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/israel_consulate_text_view"
android:text=""
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:layout_width="30dp"
android:layout_gravity="center_vertical"
android:layout_height="30dp"
android:src="#android:drawable/sym_action_call"
android:id="#+id/israel_phone_button"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/chabad"/>
<LinearLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:textSize="17sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beit Chabad"
android:textColor="#000000"
android:layout_gravity="center_vertical" />
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/chabad_address_text_view"
android:text="3 Blue Street, USA"
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/chabad_number_text_view"
android:text="+44 456 3245234"
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:layout_width="30dp"
android:layout_gravity="center_vertical"
android:layout_height="30dp"
android:src="#android:drawable/sym_action_call"
android:id="#+id/chabad_phone_button"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Thanks very much, I can't figure this one out.
I also had the same problem and by adding a TableLayout inside ScrollView solved the problem for me. Then, add your content (RelativeLayout) inside TableLayout.
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<-- Your RelativeLayout goes here -->
</TableLayout>
</ScrollView>
Let me know if that solved the problem. Do not forget to add the attribute fillViewport=true to ScrollView so the TableLayout match it's parent's view width and height.
I made a good code in which the text 1 schedule here and 2 schedule here were aligned similar vertically. But i put this layout in list view and so the 7 names of days are not same, layout is changed.my custom layout had this code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#drawable/listback">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="25dp"
android:paddingRight="80dp"
android:gravity="center_vertical"
android:text="Day name"
android:textColor="#ffffff"
android:textStyle="bold"
android:id="#+id/dayname" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingLeft="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 schedule here"
android:textSize="20dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:id="#+id/mytext1"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 schedule here"
android:textSize="20dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:id="#+id/mytext2"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Total"
android:id="#+id/totaltext" />
</LinearLayout>
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:id="#+id/lightStatus"
android:layout_marginLeft="35dp"
android:src="#drawable/gray"/>
</LinearLayout>
</LinearLayout>
So how can i manage layout so that my 1 schedule and 2 schedule texts will be in same line vertically after i put them in list view
Image putting list view is shown
Hi you can try to this xml code hope this can help you...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#android:color/darker_gray"
android:orientation="horizontal">
<TextView
android:id="#+id/dayname"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="3dp"
android:gravity="center_vertical"
android:text="Wednesday"
android:textColor="#ffffff"
android:textSize="25sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="5dp"
android:weightSum="3">
<TextView
android:id="#+id/mytext1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="center"
android:text="Nov 18 2016 Friday"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/mytext2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="center"
android:text="no day available"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/totaltext"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="no day available"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/lightStatus"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginLeft="35dp"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>
I'am working on a metro-ish layout for android, but i can seem to make it work the same on all devices. On a Galaxy Note3 it doesn't align to the bottom (too much gap between buttons), and on a smaller screen Galaxy Ace2 it fits too crowded (some buttons next to each other)
This is my layout, any ideas on how to make it universal would be great! Thanks in advance
<?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"
android:background="#drawable/bg_login" >
<ImageView
android:id="#+id/icon_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="#drawable/logo_white" />
<Button
android:id="#+id/btn_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/gradient_feed"
android:drawableTop="#drawable/feed"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Feed"
android:textColor="#color/white"
android:textSize="10dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/btn_profile"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/gradient_profile"
android:drawableTop="#drawable/profile"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Profile"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
<Button
android:id="#+id/btn_new_challenge"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:background="#drawable/gradient_new_challenge"
android:drawableTop="#drawable/new_challenge"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="New Challenge"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
<Button
android:id="#+id/btn_rankings"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/gradient_rankings"
android:drawableTop="#drawable/rankings"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Rankings"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/btn_factory"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/gradient_factory"
android:drawableTop="#drawable/task_factory"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Task Factory"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
<Button
android:id="#+id/btn_settings"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:background="#drawable/gradient_settings"
android:drawableTop="#drawable/settings"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Settings"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
<Button
android:id="#+id/btn_gadgets"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/gradient_gadgets"
android:drawableTop="#drawable/gadgets"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Gadgets"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
</LinearLayout>
<Button
android:id="#+id/btn_store"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/gradient_store"
android:drawableTop="#drawable/store"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Store"
android:textColor="#color/white"
android:textSize="10dip" />
<Button
android:id="#+id/btn_help"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/gradient_help"
android:drawableTop="#drawable/help"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Help"
android:textColor="#color/white"
android:textSize="10dip" />
</LinearLayout>
To have content that takes the whole space height you will have to play with the weight of your child Views and their respective height.
I don't get where is your first image icon_photo. Doesn't look to be in your screenshots.
<?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"
android:background="#drawable/bg_login" >
<ImageView
android:id="#+id/icon_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:src="#drawable/logo_white" />
<Button
android:id="#+id/btn_feed"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:background="#drawable/gradient_feed"
android:drawableTop="#drawable/feed"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Feed"
android:textColor="#color/white"
android:textSize="10dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/btn_profile"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:background="#drawable/gradient_profile"
android:drawableTop="#drawable/profile"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Profile"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
<Button
android:id="#+id/btn_new_challenge"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:background="#drawable/gradient_new_challenge"
android:drawableTop="#drawable/new_challenge"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="New Challenge"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
<Button
android:id="#+id/btn_rankings"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:background="#drawable/gradient_rankings"
android:drawableTop="#drawable/rankings"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Rankings"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/btn_factory"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:background="#drawable/gradient_factory"
android:drawableTop="#drawable/task_factory"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Task Factory"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
<Button
android:id="#+id/btn_settings"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:background="#drawable/gradient_settings"
android:drawableTop="#drawable/settings"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Settings"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
<Button
android:id="#+id/btn_gadgets"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:background="#drawable/gradient_gadgets"
android:drawableTop="#drawable/gadgets"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Gadgets"
android:textColor="#color/white"
android:textSize="10dip"
android:layout_weight="1.00" />
</LinearLayout>
<Button
android:id="#+id/btn_store"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/gradient_store"
android:drawableTop="#drawable/store"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Store"
android:textColor="#color/white"
android:textSize="10dip" />
<Button
android:id="#+id/btn_help"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/gradient_help"
android:drawableTop="#drawable/help"
android:gravity="center|center_vertical"
android:padding="10dp"
android:text="Help"
android:textColor="#color/white"
android:textSize="10dip"
/>
</LinearLayout>
The difference between those screen is high. You will maybe have to play with different layouts or different box sizes using the values but if your drawables size are not the same you can probably deal without having multiple layouts.
http://developer.android.com/guide/practices/screens_support.html
I would create different layout folders for different resolution, density. I wouldn't just use one xml for all different phone sizes out there. You probably want to pick out the most popular ones and just aim for those.