2

I have simple application which has one ImageView and text box

At First I started with AppCompactActivity, it works.

However when I changed AppCompatActivity to Activity. (I would like to delete the title bar)

ImageView is disappeared(Droid).

I think I have constraint of ImageView.

How can I show the ImageView??

enter image description here

package jp.virararara.antbuid.bb;

//import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.app.Activity

//class TopActivity : AppCompatActivity() {
class TopActivity : Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_top)
    }
}

activity_top.xml

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="105dp"
    android:layout_height="208dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@+id/editText2"
    app:srcCompat="@mipmap/ic_launcher"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="16dp"
    app:layout_constraintHorizontal_bias="0.0" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="153dp"
    android:layout_marginTop="132dp"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="Name"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

whitebear
  • 11,200
  • 24
  • 114
  • 237

1 Answers1

5

I would like to delete the title bar

Then you change the theme of the Activity, it's not necessary to extend a separate class.

You don't need a FrameLayout to display an image

But the real issue is

1) app:srcCompat is meant to be loaded by an AppCompat class

Android: What is the difference between app:srcCompat=" " and android:src=" "?

2) you are using a ConstraintLayout with no constraints, and you can refer to the symptoms of that here.

ConstraintLayout views in top left corner

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Thanks for your constraintlayout idea. I have added constraint layout to the imageview. – whitebear May 27 '17 at 17:09
  • 3
    Thanks!! If I changed app:srcCompat=" " to android:src=" "? it works. however If I drop new images, xml automatically use app:srcCompat. – whitebear May 27 '17 at 17:11
  • `app:srcCompat is meant to be loaded by an AppCompat class` : what does this mean exactly? Where is this documented? `Activity` or `AppCompatActivity` are not really loading the vector drawables, are they? – Sébastien Sep 15 '22 at 20:11
  • @Sébastien The `LayoutInflater` will load the drawable resources, yes. – OneCricketeer Sep 15 '22 at 20:39