ImageView未在模拟器

时间:2017-05-11 08:02:59

标签: android xml vector

我的应用程序中有一些ImageView。它们在我的手机上显示得很好但是没有办法在模拟器上显示它们。我已经尝试过不同版本和屏幕尺寸。在另一个问题中,人们可以使用android:hardwareAccelerated="false"或使用src而不是srcCompat来解决问题,但这似乎没什么帮助。

imageViews所在的ConstraintLayout:

<android.support.constraint.ConstraintLayout
    android:id="@+id/login_header"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <ImageView
        android:id="@+id/title_background_log"
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:background="@color/colorPrimary"
        android:elevation="10dp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@color/colorPrimary" />

    <ImageView
        android:id="@+id/company_logo"
        android:layout_width="331dp"
        android:layout_height="90dp"
        android:layout_marginEnd="39dp"
        android:layout_marginLeft="39dp"
        android:layout_marginRight="39dp"
        android:layout_marginStart="39dp"
        android:elevation="15dp"
        android:scaleType="fitXY"
        android:src="@drawable/zeeromed_text"
        android:visibility="visible"
        app:layout_constraintHorizontal_bias="0.489"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="ContentDescription"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />

</android.support.constraint.ConstraintLayout>

完整的活动布局:

<android.support.constraint.ConstraintLayout
    android:id="@+id/login_header"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <ImageView
        android:id="@+id/title_background_log"
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:background="@color/colorPrimary"
        android:elevation="10dp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@color/colorPrimary" />

    <ImageView
        android:id="@+id/company_logo"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginEnd="39dp"
        android:layout_marginLeft="39dp"
        android:layout_marginRight="39dp"
        android:layout_marginStart="39dp"
        android:elevation="15dp"
        android:scaleType="center"
        android:visibility="visible"
        app:layout_constraintHorizontal_bias="0.489"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="ContentDescription"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />

</android.support.constraint.ConstraintLayout>

<android.support.constraint.ConstraintLayout
    android:id="@+id/login_body"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="0dp"
    android:layout_marginLeft="0dp"
    android:layout_marginRight="0dp"
    android:layout_marginTop="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/login_header">

    <EditText
        android:id="@+id/email_editText"
        style="@android:style/Widget.EditText"
        android:layout_width="0dp"
        android:layout_height="45dp"
        android:layout_marginEnd="30dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginStart="30dp"
        android:layout_marginTop="136dp"
        android:background="@drawable/rounded_transparent_button_focusable"
        android:ems="10"
        android:hint="@string/email_hint"
        android:inputType="textEmailAddress"
        android:paddingLeft="10dp"
        android:selectAllOnFocus="false"
        android:textAlignment="viewStart"
        android:textColor="@color/colorPrimary_text"
        android:textColorHint="@color/colorSecondary_text"
        android:textSize="18sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="37dp"
        android:text="oppure"
        android:textAlignment="center"
        android:textColor="@color/colorPrimary_text"
        android:textSize="14sp"
        app:layout_constraintHorizontal_bias="0.486"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/send_button"
        tools:ignore="HardcodedText,RtlHardcoded" />

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:background="@color/colorAccent"
        android:visibility="invisible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
        android:id="@+id/send_button"
        style="@android:style/Widget.Material.Button"
        android:layout_width="300dp"
        android:layout_height="48dp"
        android:layout_marginBottom="81dp"
        android:layout_marginEnd="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginStart="32dp"
        android:background="@color/colorPrimary"
        android:elevation="10dp"
        android:text="accedi"
        android:textColor="@color/white"
        android:textSize="18sp"
        app:layout_constraintBottom_toTopOf="@+id/sing_in"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:spinning_bar_color="#FFFFFF"
        app:spinning_bar_width="4dp"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />

    <Button
        android:id="@+id/security_button"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="65dp"
        android:layout_height="60dp"
        android:layout_marginBottom="29dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="15dp"
        android:background="@drawable/hexagon_lock"
        android:backgroundTint="@color/black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.055"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        tools:ignore="RtlHardcoded" />

    <Button
        android:id="@+id/login_intro_button"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="197dp"
        android:layout_height="48dp"
        android:layout_marginBottom="89dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:text="Ripeti introduzione"
        android:textColor="@color/colorPrimary_text"
        android:textSize="12sp"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        tools:ignore="HardcodedText" />

    <Button
        android:id="@+id/sing_in"
        style="@android:style/Widget.DeviceDefault.Button.Borderless"
        android:layout_width="300dp"
        android:layout_height="48dp"
        android:layout_marginBottom="122dp"
        android:layout_marginEnd="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginStart="15dp"
        android:text="@string/registration_link"
        android:textAppearance="@android:style/TextAppearance.Material.Body2"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />

    <TextView
        android:id="@+id/security_text"
        android:layout_width="65dp"
        android:layout_height="15dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:text="Sicurezza"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:textSize="12sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.432"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/innovation_text"
        tools:ignore="HardcodedText,RtlHardcoded" />

    <TextView
        android:id="@+id/innovation_text"
        android:layout_width="65dp"
        android:layout_height="15dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="16dp"
        android:text="Innovazione"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:textSize="12sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.487"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        tools:ignore="HardcodedText,RtlHardcoded"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintTop_creator="1" />

    <Button
        android:id="@+id/innovation_button"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="65dp"
        android:layout_height="60dp"
        android:layout_marginBottom="29dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="15dp"
        android:background="@drawable/hexagon_cloud"
        android:backgroundTint="@color/black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.488"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        tools:ignore="RtlHardcoded" />

    <EditText
        android:id="@+id/password_editText"
        style="@android:style/Widget.EditText"
        android:layout_width="0dp"
        android:layout_height="45dp"
        android:layout_marginBottom="302dp"
        android:layout_marginEnd="30dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginStart="30dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/rounded_transparent_button_focusable"
        android:ems="10"
        android:hint="@string/password_hint"
        android:inputType="textPassword"
        android:paddingLeft="10dp"
        android:selectAllOnFocus="false"
        android:textAlignment="viewStart"
        android:textColor="@color/colorPrimary_text"
        android:textColorHint="@color/colorSecondary_text"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/email_editText"
        app:layout_constraintVertical_bias="0.414"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />
</android.support.constraint.ConstraintLayout>

我不认为我的布局结构是问题,但也许你可能证明我错了。 图片显示在API 24 Nougat 7.0手机上。 我尝试了从API 21到23的模拟器,因为我的最小API是21。

2 个答案:

答案 0 :(得分:0)

我真的不知道为什么scr无法正常工作,但是您可以尝试: android:background="@drawable/zeeromed_text" 代替 : android:src="@drawable/zeeromed_text"scrCompact 不要像在第一个background

上混合srcImageView那样做多个

答案 1 :(得分:0)

这样更改

for (index, value) in controlArr.enumerated() {
        print("\(index): \(value)")

        let  yPosition : Int = index+1
        DispatchQueue.main.async {                    

            let categoryField =  UITextField(frame: CGRect(x: 15, y: 84*yPosition+35, width: Int(self.view.frame.width - 35), height: 40))
            // categoryField.placeholder = "Please Enter \(value)"
            categoryField.font = UIFont.systemFont(ofSize: 15)
            categoryField.text  = "\(self.fieldArr[index])"
            categoryField.delegate = self
            categoryField.tag = 100 + index
           // self.myDict["myTextfield\(index)"] = categoryField

            categoryField.borderStyle = UITextBorderStyle.bezel
            categoryField.autocorrectionType = UITextAutocorrectionType.no
            categoryField.keyboardType = UIKeyboardType.default
            categoryField.returnKeyType = UIReturnKeyType.done
            categoryField.clearButtonMode = UITextFieldViewMode.whileEditing;
            categoryField.contentVerticalAlignment = UIControlContentVerticalAlignment.center

            self.arrayOfTextFields.append(categoryField)
            self.scrollView.addSubview(categoryField)

            for item in self.controlArr {

                let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 40, height: 20))

                if item == "dropdown"
                {
                    categoryField.rightViewMode = UITextFieldViewMode.always
                    imageView.contentMode = .scaleAspectFit
                    let image = UIImage(named:"down.png")
                    imageView.image = image
                    categoryField.rightView = imageView

                }else{

                    imageView.isHidden = true
                }

            }
   }         

Reference

希望这可能对您有帮助