I've search thoroughly but it doesn't appear that this is a common problem -- this may be increased by the fact that I'm still new and don't really know what to look for in this regard.
Regardless, the last time that I ran this code it worked fine however, now the display is simply white -- so even with the black writing it doesn't show up. Thank you very much for any help you can offer.
The xml code is below:
<?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"
tools:context=".MainActivity">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:src="#drawable/background" />
<TextView
android:id="#+id/mocha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/price_mocha"
android:layout_alignParentStart="true"
android:layout_marginStart="15dp"
android:text="Price of mocha"
android:textColor="#060505" />
<TextView
android:id="#+id/price_mocha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="234dp"
android:layout_marginStart="35dp"
android:text="3.99"
android:textColor="#ffffff" />
</RelativeLayout>
Related
By developing a simple screen, and putting a simple text and putting two check boxes to test, as you can see:
https://uploaddeimagens.com.br/imagens/fTCpBp0
I'm showing the image through another website, just because I'm not able to upload the image to this website, ok?
Sorry about that, but it's really necessary to show.
It is not even possible to move the checkboxes. That is, the checkboxes do not move. Please how to fix?
Code:
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/corDeFundo"
android:orientation="vertical">
<TextView
android:id="#+id/textoDosSintomas1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
android:layout_marginBottom="453dp"
android:text="Testing Responsiveness on Android"
android:textColor="#color/corPreta"
android:textSize="80px"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CheckBox"
android:textSize="80px"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkBox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CheckBox"
android:textSize="80px"
android:textStyle="bold" />
</LinearLayout>
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 wrote some very simple code with one image and two text views in a Relative Layout.
It all seems fine in the preview but as soon as I try to run the code on my phone, one text view disappears.
I have tried everything, but can't fix the problem (check out the screenshots).
Code in Android Studio Preview
Code on my smartphone
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/hb_isabel"
android:contentDescription="TODO"
android:scaleType="centerInside"
android:src="#drawable/androidparty"
/>
<TextView
android:id="#+id/hb_isabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Happy Birthday,Isabel!"
android:textSize="36sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="From, Nathalie"
android:textSize="36sp"
/>
</RelativeLayout>
Is there anyone who can help me out?
i noticed recently when i checked my app in android 4.1.1 that my content goes off the screen but works very well in 4.2.2 above. Please check the screenshot.
and yes, its a bilingual app (English/Tamil). After few research i found out that English ListItem works well but Tamil causes problem
Layout Code :
activity_latest_news.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
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=".LatestNews" >
<ListView
android:id="#+id/LatestNewsView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</ListView> </RelativeLayout>
latest_news_single_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/LatestNews_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/latest_news_dummy_title"
android:textSize="15sp" />
<TextView
android:id="#+id/LatestNews_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#id/LatestNews_title"
android:text="#string/latest_news_dummy_desc"
android:textColor="#color/getCCC"
android:textSize="14sp" />
<TextView
android:id="#+id/LatestNews_posted_on"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/LatestNews_description"
android:paddingLeft="3dp"
android:paddingTop="2dp"
android:text="#string/latest_news_posted"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#911991" />
<ImageView
android:id="#+id/latest_news_addfav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/LatestNews_posted_on"
android:src="#drawable/star"
android:layout_alignParentRight="true" />
</RelativeLayout>
Is this Unicode issue? or layout problem?
And also please take a look at both emulator. if u notice, in 4.1.1 the theme is like greyish white while in 4.2.2 is complete white.. and even the drawable (refresh image) is looking weird (Yea, i know i haven't setup separate drawable for mdpi,hdpi etc) But what causes the difference? Is this App Theme issue?
Any help will be much appreciated. Thank you!
Try changing your layouts as below and check what happens.
your listview layout :
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LatestNewsView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
Row Layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/LatestNews_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/latest_news_dummy_title"
android:textSize="15sp" />
<TextView
android:id="#+id/LatestNews_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/LatestNews_title"
android:text="#string/latest_news_dummy_desc"
android:textColor="#color/getCCC"
android:textSize="14sp" />
<TextView
android:id="#+id/LatestNews_posted_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/LatestNews_description"
android:paddingLeft="3dp"
android:paddingTop="2dp"
android:text="#string/latest_news_posted"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#911991" />
<ImageView
android:id="#+id/latest_news_addfav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/LatestNews_posted_on"
android:src="#drawable/star"
android:layout_alignParentRight="true" />
</RelativeLayout>
Image problem:
as you can see one emulator is Nexus S and one is Nexus One so there is a difference in their ppi values which is causing the problem. you need to set appropriate image for corresponding density.
Update :
check this it may help
Try and manually specify the number of lines for each text view. For instance, change the first TextView to look like this:
<TextView
android:id="#+id/LatestNews_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:singleLine="false"
android:maxLines="3"
android:ellipsize="end"
android:text="#string/latest_news_dummy_title"
android:textSize="15sp" />
Note that I added:
android:singleLine="false" <!-- Allows content to wrap into other lines -->
android:maxLines="3" <!-- Makes maximum no. of line wraps = 3 -->
android:ellipsize="end" <!-- Adds an ellipsis (...) to the end of line-->
Side note: you're mixing fill_parent and match_parent. They do the same thing. For more consistency, stick to match_parent.
EDIT: Also, get rid of layout_alignParentRight="true". I don't think you need it because the width is already going to fill the parent view. Using layout_alignParentLeft="true" is sufficient since both English and Tamil are written left-to-right.
I have an application called "Yamba". The only layout XML file it has is:
<?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" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/titleStatus"
android:textSize="30sp" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top|center_horizontal"
android:hint="#string/hintText" />
<TextView
android:id="#+id/textCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:text="000" />
<Button
android:id="#+id/buttonId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/buttonUpdate"
android:textSize="20sp" />
</LinearLayout>
The application shows everything well.
The only change I made is changing the order of (EditText id/editText") with (TextView id/textCounter) so that it becomes:
<?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" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/titleStatus"
android:textSize="30sp" />
<TextView
android:id="#+id/textCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:text="000" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top|center_horizontal"
android:hint="#string/hintText" />
<Button
android:id="#+id/buttonId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/buttonUpdate"
android:textSize="20sp" />
</LinearLayout>
After this change the emulator shows me: Unfortunately, Yamba has stopped" OK.
When I restore it back to its previous order, everything works well. why?
When you change the order of Views in the XML layout, their numerical IDs are changed (they are assigned from top to bottom), then when you refer to the previous ID in your code for example in findViewById() you'll get the wrong one and an ClassCastException (I guess because you didn't include the logcat).
Cleaning before building will solve the problem.
When in doubt with things that don't make sense. Project Clean/Exit eclipse and reopen.
I've encounter strange things like this before and that's ultimately what solved it.