Android Imageview徽标未显示
我有一个Android Imageview徽标未显示,android,android-layout,Android,Android Layout,我有一个main_activity.xml,它显示了一个碎片化的布局。布局包含imageview(一个徽标)和一些文本字段。起初,我尝试使用relativelayout,它在设计视图上看起来很棒/完美。但在模拟器上运行时,一切都会变得混乱。所以我决定使用线性布局。更改后,UI有了改进。但问题是图像没有显示出来 <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_con
main_activity.xml
,它显示了一个碎片化的布局。布局包含imageview
(一个徽标)和一些文本字段
。起初,我尝试使用relativelayout
,它在设计视图上看起来很棒/完美。但在模拟器上运行时,一切都会变得混乱。所以我决定使用线性布局
。更改后,UI有了改进。但问题是图像没有显示出来
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout02">
<ImageView
android:id="@+id/imageView"
android:layout_width="276dp"
android:layout_height="276dp"
app:srcCompat="@drawable/splash_logob"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="276dp"
android:inputType="textPersonName"
android:text=""
android:hint="URL"
android:ems="10"
android:id="@+id/siteurl"
android:height="24sp"
android:layout_gravity="center"
android:background="@color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:gravity="center"
android:paddingTop="3dp"
android:layout_centerHorizontal="true"
android:paddingLeft="5dp"
android:textAlignment="viewStart" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="276dp"
android:inputType="textPassword"
android:text=""
android:hint="Password"
android:ems="10"
android:id="@+id/password"
android:height="24sp"
android:layout_gravity="center"
android:background="@color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:gravity="center"
android:paddingTop="3dp"
android:layout_centerHorizontal="true"
android:paddingLeft="5dp"
android:layout_marginTop="17dp" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="276dp"
android:inputType="textPersonName"
android:hint="username"
android:ems="10"
android:id="@+id/username"
android:height="24sp"
android:layout_gravity="center"
android:background="@color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:gravity="center"
android:paddingTop="3dp"
android:layout_centerHorizontal="true"
android:paddingLeft="5dp"
android:layout_marginTop="17dp" />
</RelativeLayout>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:textColor="@color/textcolor"
android:id="@+id/scannedresult"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/scanbtn"
android:layout_alignStart="@+id/scanbtn" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_height="wrap_content"
android:textColor="@color/textcolor"
android:text="QR Scanner"
android:id="@+id/scanbtn"
android:layout_width="wrap_content"
android:layout_alignRight="@+id/secretkey"
android:layout_alignEnd="@+id/secretkey"
android:layout_below="@+id/secretkey"
android:layout_alignBottom="@+id/login"
android:layout_weight="1" />
<Button
android:text="Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="do_login"
android:layout_below="@+id/secretkey"
android:layout_alignLeft="@+id/secretkey"
android:layout_alignStart="@+id/secretkey"
android:id="@+id/login"
android:layout_weight="1" />
</LinearLayout>
<EditText
android:layout_width="wrap_content"
android:inputType="textPersonName"
android:text=""
android:hint="Secret Key"
android:height="24sp"
android:ems="10"
android:id="@+id/secretkey"
android:background="@color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:paddingLeft="5dp"
android:layout_marginTop="17dp"
android:layout_below="@+id/password"
android:layout_alignLeft="@+id/password"
android:layout_alignStart="@+id/password"
android:layout_alignRight="@+id/password"
android:layout_alignEnd="@+id/password" />
问题是当我运行时,它没有显示图像徽标。怎么了
使用:
android:src="@drawable/splash_logob"
而不是:
app:srcCompat="@drawable/splash_logob"
srccomat
属性是在AppCompat
库中定义的。如下更改图像视图
<ImageView
android:id="@+id/imageView"
android:layout_width="276dp"
android:layout_height="276dp"
android:src="@drawable/splash_logob"
android:layout_centerHorizontal="true"
/>
您是否在所有可绘制文件夹(可绘制xhdpi、可绘制ldpi等)中添加了“splash_logob”?请使用android:src=“@drawable/splash_logob”而不是app:srcCompat=“@drawable/splash_logob”谢谢!是的,是的。AbhayBohra-是的,这似乎是个问题,有个英雄。你谢谢