I've been working on my app and i've come across an issue where in the preview, whenever i place text below the button for example the "roomservice" button it doesnt show it on the emulator when running but it does in the preview. What am i doing wrong here?
This is my xml code as its the only coding part i've been working on, i've also added android:layout_below="#id/roomservice"/> in the textview but it still did not work.
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
tools:context=".MainMenu">
<ImageButton
android:id="#+id/roomservice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="26dp"
android:layout_marginLeft="26dp"
android:layout_marginTop="95dp"
app:srcCompat="#drawable/ic_room_service_black_24dp" />
<TextView
android:id="#+id/textView"
android:layout_width="100dp"
android:layout_height="37dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="34dp"
android:layout_marginLeft="34dp"
android:layout_marginBottom="497dp"
android:text="Room Service"
android:textColor="#F8F1F5F4"
android:textFontWeight="14"
android:layout_below="#id/roomservice"/>
<ImageButton
android:id="#+id/transportation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginStart="237dp"
android:layout_marginLeft="237dp"
android:layout_marginTop="238dp"
app:srcCompat="#drawable/ic_taxi" />
<ImageButton
android:id="#+id/foodservice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="239dp"
android:layout_marginLeft="239dp"
android:layout_marginTop="92dp"
app:srcCompat="#drawable/ic_restaurant" />
<ImageButton
android:id="#+id/maintenance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="234dp"
app:srcCompat="#drawable/ic_maintenance" />
<ImageButton
android:id="#+id/checkout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="26dp"
android:layout_marginLeft="26dp"
android:layout_marginTop="368dp"
app:srcCompat="#drawable/ic_checkout" />
<ImageButton
android:id="#+id/baggagecollection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="234dp"
android:layout_marginLeft="234dp"
android:layout_marginTop="373dp"
app:srcCompat="#drawable/ic_bag" />
Try removing the line:
android:layout_alignParentStart="true"
from the markup for the textview. This parameter, according to the documentation, will "make the start edge of this view match the start edge of the parent". Both the TextView and The first ImageButton have the same parent (the layout), so your views could be generating on top of each other.
The 'start' position is also dependent on on the locale setting of the device. This might explain why the layout is displaying differently across devices.
Related
Back button disappear even though i called layout below the recycler view, I can show the button if i set the height manually but i need to use "wrap_content" because not all devices have the same size. Im trying to add a back button on the bottom after the recycler view. pls help on why it dosent show.. Im new in android studio ive tried changing the layouts but dosent work..
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#color/colorLight">
<SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/search_view_bg"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:queryHint="Search"
android:iconifiedByDefault="false"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/viewMain"
android:layout_below="#id/searchView"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
<Button
android:id="#+id/back"
android:layout_width="187dp"
android:layout_height="50dp"
android:text="Go Back"
android:layout_marginTop="5dp"
android:textStyle="bold"
android:layout_below="#id/viewMain"
android:textSize="14sp"
android:fontFamily="#font/varela_round"
android:layout_centerHorizontal="true"
android:background="#drawable/round_back_white"
/>
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/searchView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/viewMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
</androidx.recyclerview.widget.RecyclerView>
<Button
android:id="#+id/back"
android:layout_width="187dp"
android:layout_height="50dp"
android:layout_below="#id/viewMain"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="#drawable/round_back_white"
android:fontFamily="#font/varela_round"
android:text="Go Back"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
#xenxen101219 After SearchView Use NestedScrollView
I have a problem with layout in my app that I am writing. I want to make some domestic changes like buttons to be in one column and they should be on right hand side. Additionally EditText with Buttons should be around middle of the screen ( I attach screenshot of how it looks for now). After reading few of similar problems the main idea was to modify textView1 on layout_width="fill_parent", but that doesnt make any difference. Most of changes that I am trying doesnt seems to have any effect, do you know why ?Current Layout
I am also giving the adapter view layout xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<TextView
android:gravity="center"
android:text="TextView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/textView1"
android:textSize="18sp"
android:layout_weight="66.6"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="33.3">
<Button
android:id="#+id/removeBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_btn_remove"
android:backgroundTint="#color/black" />
<EditText
android:id="#+id/itemAmount"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_horizontal"
android:inputType="number"
android:minEms="1"
android:text="1"
android:textAlignment="center"
android:textAllCaps="false"
android:textColor="#android:color/black"
android:textSize="20sp" />
<Button
android:id="#+id/addBtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_btn_add"
android:backgroundTint="#color/black" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_marginLeft="60dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:clickable="true"
app:fabCustomSize="40dp"
app:srcCompat="?android:attr/textCheckMarkInverse" />
</LinearLayout>
</LinearLayout>
I am writing a code with a few nested layouts. As I have used material design I also wanted to set elevation. Though elevation was working fine with the elements of outermost layout, the contents of the inner LinearLayout (nested inside a CoordinatorLayout) is not casting shadows despite setting elevation.
<?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"
android:background="#color/white"
tools:context="com.joblesscoders.aditya.todolist.HomeActivity">
<TextView
android:layout_width="match_parent"
android:id="#+id/count"
android:text="Main Activity"
android:textSize="20dp"
android:elevation="5dp"
android:textColor="#color/white"
android:gravity="center_vertical"
android:background="#color/colorPrimary"
android:layout_height="50dp" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/cly"
android:background="#color/white"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/sv"
android:background="#color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lly"
android:background="#color/white"
android:orientation="vertical">
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<TextView
android:text="Task here"
android:id="#+id/tid"
android:textSize="40sp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:elevation="4dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_height="wrap_content" />
<!-- More TextViews to suit purpose -->
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="#drawable/ic_add2"
app:rippleColor="#color/white"
android:id="#+id/fab"
android:layout_gravity="bottom|end"
/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
This code in android studio designer view produces the expected result i.e.
the TextViews displaying "Task here" have required shadows, but as soon I run it on a android 6.O custom device, the page becomes:
I would be thankful if anybody corrects me or advices on the dos and don'ts. I am extremely new to android programming, and this is my first code. So please bear with me if I have made any really very silly mistake.
I'm trying to send the white image in the back of my button and text in Relative Layout. Here is the code:
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.sahni.lightspeed.starting_screen"
tools:showIn="#layout/activity_starting_screen"
android:background="#drawable/q1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title"
android:textSize="70sp"
android:id="#+id/title"
android:textColor="#00e1ff"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start_button"
android:id="#+id/button"
android:textSize="20sp"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:onClick="buttonOnClick"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView"
android:layout_alignLeft="#+id/title"
android:layout_alignStart="#+id/title"
android:layout_below="#+id/title"
android:background="#ffffff" />
</RelativeLayout>
The layout sets for the image aren't correct, but I don't know which ones to use to get the output I want. A screenshot of current output:
Am I using the best layout for this problem ?
Can someone please explain to me how the solution works too?
Just move to first ImageView in your RelativeLayout :
<RelativeLayout ... >
<ImageView ... />
<TextView ... />
<Button ... />
</RelativeLayout>
Your ImageView has android:layout_below="#+id/title" property so it' always below your title, so it can't be in background of your title.
I am developing photo Editor in android Studio . I have images and icons on my screen which is not fit to other screens(different sizes). I have included following support screen code in my manifest.xml file
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
I came to know that density independence is the way to get rid of this. I don't know how to proceed further .please help me what are the steps to make my App density independence?
activity_main.xml
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical|center"
android:background="#403E3E">
<LinearLayout
android:layout_marginTop="30px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<SeekBar
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:max="200"
android:progress="100"
android:id="#+id/seekBar1" />
</LinearLayout>
<LinearLayout
android:id="#+id/middle_layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:id="#+id/imageView2"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher"
android:layout_gravity="center_vertical"
android:background="#ff0e0e0e" />
<SlidingDrawer
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:content="#+id/content"
android:handle="#+id/handle"
android:id="#+id/slidingDrawer"
android:orientation="horizontal"
android:alpha="0.5"
android:layout_gravity="right|top">
<LinearLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#11111111"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/brighticn"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:background="#drawable/brighticon"
android:layout_gravity="center_vertical" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/filtericn"
android:background="#drawable/filters" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/handle"
android:background="#drawable/move" />
</SlidingDrawer>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_gravity="bottom">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_gravity="bottom"
android:background="#ff030101">
<LinearLayout
android:id="#+id/sublayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ff030101">
<Button
android:id="#+id/buttonhide"
android:text="txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
To truly be able to have a density independent app, you need to provide your resources in different resolutions. Android is really smart on handling those.
When adding images you should create smaller images, or larger images, based on the format of the screen you want to support and put them in specific folder for that format. Something like this:
res/
drawable/
icon.png
background.png
drawable-hdpi/
icon.png
background.png
This would make Android use drawable/icon.png when you have any other screen density than hdpi. But will use drawable-hdpi/icon.png for that specific type of screen.
To understand this better, you can read this very detailed guide from the Android docs: http://developer.android.com/guide/topics/resources/providing-resources.html