Please help me! My App Background won't appear on my mobile device upon running the project.
What might be the problem? I already lessen the resolution of my background image but still no progress. The output won't appear. But if I remove the background it would appear instantly.
Here's the code:
<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="#drawable/bg"
tools:context=".MainActivity" >
<ImageView
android:layout_width="290dp"
android:layout_height="200dp"
android:src="#drawable/logo"
android:id="#+id/imageView"
android:contentDescription="#string/my_logo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="240dp"
android:src="#drawable/mr_hertz"
android:id="#+id/mr"
android:contentDescription="#string/mr_hertz_"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="290dp"/>
<ImageButton
android:layout_width="140dp"
android:layout_height="40dp"
android:src="#drawable/account"
android:id="#+id/account"
android:layout_below="#+id/mr"
android:layout_centerHorizontal="true"
android:contentDescription="#string/my_account" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/member_"
android:textColor="#f0fffc"
android:id="#+id/member"
android:textSize="12sp"
android:textStyle="bold|italic"
android:layout_below="#+id/account"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="100dp"
android:layout_height="15dp"
android:src="#drawable/sign_in"
android:id="#+id/sign"
android:contentDescription="#string/sign_in_"
android:layout_below="#+id/member"
android:layout_alignLeft="#+id/member"
android:layout_alignStart="#+id/member" />
</RelativeLayout>
If your entire layout is empty, try removing:
tools:context=".MainActivity"
Otherwise, if your view appears correctly in the Graphical Layout part of the editor, something is wrong with your image. Try using another.
Related
I am new to android programming but I know how everything works, recently I was trying to create an app just like uber after I finished creating the launch activity i tested it on my actual device just to check whether everything looks fine but when I launched it on my device everything (layouts, imageViews, Textviews..etc) were misplaced, I have never had this problem before its just this time. could anyone please tell me where am I going wrong?
I am attaching screenshots below.
<?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="#ffffff"
tools:context="com.example.keyur.uber.MainActivity">
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/layout1"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/showtext"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:fontFamily="monospace"
android:text="#string/get_moving_with_uber"
android:textColor="#000000"
android:textSize="20sp"
android:typeface="monospace" />
<ImageView
android:layout_width="40dp"
android:id="#+id/imgv"
android:layout_height="30dp"
android:layout_below="#id/showtext"
android:layout_marginLeft="30dp"
android:background="#drawable/india"
/>
<TextView
android:layout_width="40dp"
android:id="#+id/countrycode"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginStart="13dp"
android:layout_toEndOf="#+id/imgv"
android:text="#string/_91"
android:textColor="#000000"
android:textSize="22sp"
android:fontFamily="monospace"
/>
<EditText
android:id="#+id/editText"
android:layout_width="250dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="#ffffff"
android:fontFamily="monospace"
android:hint="#string/enter_your_mobile_number"
android:textColor="#000000"
android:textColorHint="#484848"
android:textSize="17sp"
android:inputType="number"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="400dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imgone"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#drawable/layoutbg" />
</RelativeLayout>
</LinearLayout>
screenshots-
this is what the app looks on pixel 4 as it is set on default.
enter image description here
this is what it looks when I switch it to pixel xl, everything gets messed up
enter image description here
Due do you are fixing the layout hight an width so each and very device have different screen size. You should use match_parent and wrap_content. If you want to split all device space in the same manner, you have to use weight.
How to use weight reference
Either you can go for "Weight Sum", or you should set your
TextView for country-code "layout_toRightOf" to image view
instead of "layout_toEndOf".
I am trying to achieve the view present in the below picture
I tried all possible solution that I found but didn't worked for me
My tried code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/fab_margin">
<com.pkmmte.view.CircularImageView
android:layout_width="105dp"
android:layout_height="105dp"
android:src="#drawable/des"
android:elevation="1dp"
app:border="true"
app:border_color="#864543"
app:border_width="8dp"
app:shadow="false"
android:id="#+id/view" />
<TextView
android:layout_width="match_parent"
android:layout_height="110dp"
android:background="#435467"
android:layout_alignBottom="#+id/view"
android:layout_alignParentStart="true"
android:layout_marginStart="50dp"
android:foregroundGravity="center"
android:layout_marginEnd="#dimen/fab_margin"/>
</RelativeLayout>
I have tried below link ticked ans and also try to manipulate it according to my view but didn't succeed
How to create EditText with rounded corners?
Is I am on right way? This cant be achieved by making a XML in drwable and use it as background??
Make TextView lower than ImageView.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="105dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.pkmmte.view.CircularImageView
android:layout_width="105dp"
android:layout_height="105dp"
android:src="#drawable/des"
android:elevation="1dp"
app:border="true"
app:border_color="#864543"
app:border_width="8dp"
app:shadow="false"
android:id="#+id/view" />
<TextView
android:layout_centerVertical="true"
android:text="111"
android:textColor="#000000"
android:paddingLeft="55dp"
android:gravity="left|center_vertical"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginStart="50dp"
android:background="#FFFFFF"/>
</RelativeLayout>
i got a very weird type of problem while developing a basic android app.
While I've created an app in which the background image of an app is visible to all the devices except nexus devices of android marshmallow. Kindly help me in solving the error.
Below is the code and screenshot attached.
<?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="#drawable/abst"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="project.scytech.mi_agenda.LoginActivity">
<include
android:id="#+id/linearLayout"
layout="#layout/appname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/loginLayout"
android:layout_centerHorizontal="true"
android:orientation="horizontal" />
<LinearLayout
android:id="#+id/loginLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
android:paddingTop="16dp">
<EditText
android:id="#+id/editTextDomainName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/domainName"
android:inputType="textUri"
android:textColorHint="#FFF8E5" />
<EditText
android:id="#+id/editTextUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/username"
android:textColorHint="#FFF8E5" />
<EditText
android:id="#+id/editTextPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:fontFamily="#string/username"
android:hint="#string/password"
android:inputType="textPassword"
android:textColorHint="#FFF8E5" />
<Button
android:id="#+id/buttonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginTop="16dp"
android:clickable="true"
android:onClick="loginClicked"
android:text="#string/login" />
</LinearLayout>
</RelativeLayout>
Please try to use an ImageView and set it as background.
It means:
Use a RelativeLayout or a FrameLayout and define your ImageView as the
first child. The first objects defined are the lowest in the z-order
(i.e. they will be "below" the other views).
From: Setting an ImageView to the background Android
To fit it to whole screen device use match_parent or android:scaleType="fitXY"
Your code should look like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
tools:ignore="ContentDescription" />
//Rest of widgets......
Check also: How to make image fill RelativeLayout background without stretching
It should work
I need to create a layout something similar to below picture. My problem is how can I rotate text view and add a background to it. Tried custom textview with draw rotated. But cant position correctly with that method
<Button
android:id="#+id/dealItemPerc"
android:layout_width="150dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:fontFamily="sans-serif-light"
android:background="#drawable/deal_percentage_back"
android:rotation="-45"
android:text="TextView"
android:textColor="#color/app_black"
android:textSize="14sp" />
Tried with a button but that also not worked because cant position correctly.
Created like this. rotated frame layout with text view inside of it. Don't know why the heck someone gave minus rate.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<me.dushyantha.mywebserviceapp.SquareImageView
android:id="#+id/dealItemImage"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:scaleType="fitXY"
android:src="#drawable/detail_rounded_block" >
</me.dushyantha.mywebserviceapp.SquareImageView>
<FrameLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:rotation="-45"
>
<TextView
android:id="#+id/dealItemPerc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="TextView"
android:textSize="14sp"
android:textColor="#color/white"
android:background="#drawable/deal_percentage_back"
/>
</FrameLayout>
</RelativeLayout>
activity_main.xml
<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"
tools:context="com.example.test1.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="25dip"
android:background="#android:color/black"
android:padding="5dip"
android:rotation="-45"
android:text="Hello World"
android:textColor="#android:color/white" />
</RelativeLayout>
Nothing to do with java code
Build and run the project.
Done
I just started learning android, in my application I can switch between two fragments, I have a problem when the orientation of the screen changes, in the logCat I get the red strings:
08-24 13:14:20.970: E/SpannableStringBuilder(22708): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-24 13:14:20.980: E/SpannableStringBuilder(22708): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
the app does not crash, but the two fragments are overlapped.
this is my layout:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.eximia.lamiaspesaapp.app.ScanActivity"
android:background="#drawable/fondale">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
<ImageView
android:id="#+id/imageView"
android:layout_width="fill_parent"
android:layout_height="51dp"
android:layout_alignParentTop="true"
android:layout_marginTop="13dp"
android:background="#drawable/titolo_top"
android:contentDescription="#string/titolotop"
android:paddingLeft="100dp"
android:scaleType="fitXY" />
and my two fragments:
fragment_scan:
<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"
tools:context="com.eximia.lamiaspesaapp.ScanFragment">
<!-- TODO: Update blank fragment layout -->
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/carica_button"
android:background="#drawable/ico_carica"
android:layout_below="#+id/dispensa_button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="5dp" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/scarica_button"
android:background="#drawable/ico_scarica"
android:layout_alignTop="#+id/carica_button"
android:layout_alignLeft="#+id/scan_button"
android:layout_alignStart="#+id/scan_button" />"/>
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/dispensa_button"
android:background="#drawable/ico_prodotti"
android:layout_marginTop="63dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/scan_button"
android:background="#drawable/ico_verifica"
android:layout_alignTop="#+id/dispensa_button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
fragment_product:
<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"
tools:context="com.eximia.lamiaspesaapp.ProductFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:id="#+id/scan_format"
android:layout_width="133dp"
android:layout_height="90dp"
android:textIsSelectable="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/scan_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_centerHorizontal="true"
android:layout_below="#id/scan_format"
/>
<ImageView
android:contentDescription="#string/immagine_prodotto"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:id="#+id/immagine_prodotto"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/testo_descrizione"
android:layout_below="#+id/immagine_prodotto"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="20dp"
android:text="Large Text"
android:id="#+id/testo_prodotto"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/testo_descrizione"
android:layout_alignStart="#+id/testo_descrizione" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Modalità"
android:id="#+id/testo_sviluppo"
android:layout_centerVertical="true"
android:gravity="center"
android:layout_below="#+id/immagine_prodotto" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ratingBar"
android:paddingBottom="0dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="11dp" />
somebody says that is related third part library that my phone "samsung galaxy star" uses; how can I see if this is my case?
I do have the same error all the time. In my case It is from SwiftKey keyboard applocation, If i Switch to AOSP keyboard it is not there anymore. You don't have worry about this error it wont crash your app in anyway.
If you are having problems with fragments while rotating the screen most likely because of your logic in creating the activity/adding fragments.Remember by default when you rotate your screen the whole activity is recreated (ie. on create is called again + all saved fragments resotred). put a break point on create and rotate you might see whats the problem. usally this is tackled by checking for a fragment before adding. post some of your code if possible.