Android 线性布局中的启动屏幕图像背景不适合
我在闪屏活动中使用了一个图像作为线性布局的背景,但它显示不适合屏幕。我不知道如何使用属性来拉伸它Android 线性布局中的启动屏幕图像背景不适合,android,android-layout,imageview,android-xml,splash-screen,Android,Android Layout,Imageview,Android Xml,Splash Screen,我在闪屏活动中使用了一个图像作为线性布局的背景,但它显示不适合屏幕。我不知道如何使用属性来拉伸它 <?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:id="@+id/activity
<?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:id="@+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myproject.SplashActivity"
android:orientation="horizontal"
android:background="@drawable/my_image_background">
</LinearLayout>
正确的方法是这样的,因此请改用这个,在您的styles.xml中添加以下内容:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
在你的清单文件中添加这个
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
而@drawable/splash可能是
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@drawable/splashscreen"/>
<!-- Your product logo - 144dp color version of your app icon -->
<item>
<bitmap
android:src="@drawable/splash_logo"
android:gravity="center"/>
</item>
</layer-list>
正确的方法是这样的,因此请改用这个,在您的styles.xml中添加以下内容:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
在你的清单文件中添加这个
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
而@drawable/splash可能是
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@drawable/splashscreen"/>
<!-- Your product logo - 144dp color version of your app icon -->
<item>
<bitmap
android:src="@drawable/splash_logo"
android:gravity="center"/>
</item>
</layer-list>
这样试试
<?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:id="@+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myproject.SplashActivity"
android:orientation="horizontal"
android:background="@drawable/my_image_background">
<ImageView
android:scaleType="fitXY"
android:src="@drawable/my_image_background"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
试试这种方法。最好使用ImageView进行图像处理,因此我已按如下所示更改了您的布局&它应该可以按照您的预期工作
<?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:id="@+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myproject.SplashActivity"
android:orientation="horizontal"
android:background="@drawable/my_image_background">
<ImageView
android:scaleType="fitXY"
android:src="@drawable/my_image_background"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<?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:id="@+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.myproject.SplashActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/my_image_background" />
</LinearLayout>
最好使用ImageView进行图像处理,所以我已按如下所示更改了您的布局&它应该能按您的预期工作
<?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:id="@+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.myproject.SplashActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/my_image_background" />
</LinearLayout>
如果scaleType=fitxy不适用于imageview,请尝试以下操作 android:fitSystemWindows=true
如果scaleType=fitxy不适用于imageview,请尝试以下操作 android:fitSystemWindows=true 使用以下命令:
<?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:id="@+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myproject.SplashActivity"
android:fitSystemWindows="true"
android:orientation="horizontal"
android:scaleType="fitXY"
android:background="@drawable/my_image_background">
此代码绝对适合您的屏幕。使用此代码:
<?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:id="@+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myproject.SplashActivity"
android:fitSystemWindows="true"
android:orientation="horizontal"
android:scaleType="fitXY"
android:background="@drawable/my_image_background">
此代码绝对适合您的屏幕。首先检查图像“我的图像”背景的侧面是否有空格。如果没有,您的代码可以工作……否则您也可以尝试此代码
<?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:id="@+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myproject.SplashActivity"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:background="@drawable/my_image_background">
</RelativeLayout>
也来看看这个:::
首先检查图像“我的图像”背景的侧面是否有空格。如果没有,则代码可以工作…否则您也可以尝试此代码
<?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:id="@+id/activity_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myproject.SplashActivity"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:background="@drawable/my_image_background">
</RelativeLayout>
也来看看这个:::
他需要背景图像。如果他在Linearlayout中设置imageview,他如何放置其余的布局?你能解释一下吗?@Ahamed我刚才给了一个启动屏幕的通用示例。可以使用RelativeLayout而不是LinearLayout来解决您提出的问题。是的。你做到了。我很感激。但是,一些新的basic程序员不知道下一步该做什么。所以,给你的答案提供更多的信息,这样你就会得到更好的声誉。他需要背景图片。如果他在Linearlayout中设置imageview,他如何放置其余的布局?你能解释一下吗?@Ahamed我刚才给了一个启动屏幕的通用示例。可以使用RelativeLayout而不是LinearLayout来解决您提出的问题。是的。你做到了。我很感激。但是,一些新的basic程序员不知道下一步该做什么。所以,在你的答案上提供更多的信息,这样你就会获得更好的声誉。这里需要什么fillviewport=true。我认为这是scrollview属性。编辑您的答案。此处需要什么fillviewport=true。我认为这是scrollview属性。编辑您的答案。如果您的图像“splash_徽标”大小>2k,您可以缩放它以适合您的屏幕如果您的图像“splash_徽标”大小>2k,您可以缩放它以适合您的屏幕