skip to Main Content

Hello there I am new to programming in general, but have slowly been teaching myself.

I am currently making a very basic program that mainly uses buttons (which all work perfectly).
However Now I want to add a pricelist so I added a button like usual that takes me to the pricelist activity. (normal boring stuff all working fine). I added the pricelist (imageview) onto the page. I use photoshop to change the resolution of the pictures and i set it to 1020*1900 (I have tried making it 900*1800). Everything works perfectly on the emulator and I can see the pricelist but when I switch to my android s4 it does not show the image. The emulator i use is the small nexus default one.

I set the layout height and widths to DP instead cause I heard that might solve the problem (didnt) and I added the contentDescription line (not sure what that does) because android studio was asking me to.

I appreciate all the help I can get! thanks.

Complete Code for the activity. The buttons are just basic buttons that I keep on all my activities in order to take them back to the respective main menus.

?xml version=”1.0″
encoding=”utf-8″?>

RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/btn1"
    android:onClick="doSomething"
    android:id="@+id/machines"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/pl"
    android:id="@+id/pl"
    android:onClick="doSomething3"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/btn2"
    android:id="@+id/spares"
    android:onClick="doSomething2"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/machines"
    android:layout_toEndOf="@+id/machines"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/pricelist1" />
</LinearLayout>

I decided to add a linearlayout just for completeness, but I have tried it without it and it has made no difference. Perhaps could be something to do with the relativelayout?

2

Answers


  1. <Button
        android:id="@+id/machines"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:onClick="doSomething"
        android:text="@string/btn1" />
    
    <Button
        android:id="@+id/pl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:onClick="doSomething3" 
        android:text="@string/pl"/>
    
    <Button
        android:id="@+id/spares"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:onClick="doSomething2"
        android:text="@string/btn2" />
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/machines"
        android:orientation="vertical" >
    
        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/pricelist1" />
    </LinearLayout>
    
    Login or Signup to reply.
  2. I have tested your xml on s4 emulator and its working fine in my emulator. By making just one or two changes.

    you can test this xml that I am posting. I have made few changes related to string and image, you can change as per yours.

    Note: Image i have used for testing is of size 1020×1900 px.

       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <Button
        android:id="@+id/machines"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:onClick="doSomething"
        android:text="b1" />
    <Button
        android:id="@+id/pl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:onClick="doSomething3"
        android:text="b2_p1" />
    <Button
        android:id="@+id/spares"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:onClick="doSomething2"
        android:text="btn2" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/machines"
        android:layout_toEndOf="@+id/machines"
        android:layout_toRightOf="@+id/machines"
        android:orientation="vertical" >
        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:contentDescription="@null"
            android:src="@drawable/test2" />
    </LinearLayout>
    

    Try this and let me is it working or not…

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search