相关疑难解决方法(0)

Android启动屏幕图像大小适合所有设备

我有一个全屏PNG,我想在飞溅中显示.只有一个错误,我不知道该怎么把大小在每个绘制的文件夹(ldpi,mdpi,hdpi,和xhdpi).我的应用程序应该在所有手机和平板电脑上运行良好和美观.我应该创建什么尺寸(以像素为单位),以便在所有屏幕上显示漂亮的效果?

png android screen splash-screen drawable

207
推荐指数
8
解决办法
28万
查看次数

如何使用不调整大小的全屏背景图像(带中心裁剪)

我正在尝试将照片设置为背景Activity.我希望背景是一个全屏图像(没有边框).

因为我希望图像在没有拉伸/挤压的情况下填充整个活动的背景(即X和Y的不成比例的缩放)并且我不介意是否必须裁剪照片,我正在使用RelativeLayout带有ImageView(带android:scaleType="centerCrop")和我的布局的其余部分由a ScrollView和它的孩子组成.

<!-- Tried this with a FrameLayout as well... -->
<RelativeLayout> 
   <!-- Background -->
   <ImageView  
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scaleType="centerCrop"/>
   <!-- Form -->
   <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent">
      <ScrollView>
        <LinearLayout>
          ...
          <EditText/>
        </LinearLayout>
      </ScrollView>
   </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

问题是布局的其余部分有一些EditText视图,当软键盘出现时,ImageView会重新调整大小.我希望背景保持不变,无论软键盘是否可见.

我已经看到很多关于ImageViews被重新调整大小的问题但是(imo)没有令人满意的答案.其中大多数只是设置android:windowSoftInputMode="adjustPan"- 这并不总是实用的,特别是如果您希望用户能够滚动活动 - 或使用getWindow().setBackgroundDrawable()不裁剪图像.

我已经设法将ImageView子类化并覆盖它onMeasure()(请参阅我的答案:当键盘打开时ImageView调整大小)以便它可以强制固定的高度和宽度 - 等于设备的屏幕尺寸 - 根据标志但我是想知道是否有更好的方法来实现我想要的结果.

总而言之,我的问题是:如何将活动的背景设置为全屏照片

  • 使用scale type ="centerCrop",使照片均匀缩放(保持其纵横比),因此两个尺寸(宽度和高度)将等于或大于视图的相应尺寸;

  • 弹出软键盘时不会调整大小;


回答:

我最后关注了@pskink的建议和子类BitmapDrawable(见下面的答案).我不得不做一些调整,以确保BackgroundBitmapDrawable …

java android android-layout android-imageview background-drawable

17
推荐指数
1
解决办法
1万
查看次数

如何在LinearLayout的背景图像上设置ScaleType

我有这样的线性布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:background="@drawable/bgapp" >
Run Code Online (Sandbox Code Playgroud)

我现在需要的是设置背景图像ScaleType值以便每次填充屏幕的可能性,这是因为我要下载图像然后我将其设置为背景但没有ScaleType图像将无法保留它是基于屏幕密度的宽高比.

我找到的是这个解决方案:

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/bgapp"
    android:scaleType="centerCrop"
    android:gravity="bottom|left" />
Run Code Online (Sandbox Code Playgroud)

但它没有按预期工作..有没有办法设置LinearLayout scaleType属性或我需要更改我的布局?

android

6
推荐指数
1
解决办法
1万
查看次数

如何为所有活动设置背景?

如何为adnroid应用程序中的所有活动设置背景并保持其纵横比?

我正在使用android:windowBackground风格,但我不知道如何保持背景图像的纵横比。

是否只有ImageView手动为所有活动添加背景的方法?

android android-layout

5
推荐指数
1
解决办法
4875
查看次数

在自定义视图中设置背景图像

我创建了一个扩展 View 类的类。

public class SplashScreen extends View
Run Code Online (Sandbox Code Playgroud)

我通过设置 contentview 来使用它

View splash = new SplashScreen(this);
setContentView(splash);
Run Code Online (Sandbox Code Playgroud)

我需要设置背景图片,但我不能使用布局。我想我需要画画布,但我不知道该怎么做。

protected void onDraw(Canvas canvas) {
  ballBounds.set(ballX-ballRadius, ballY-ballRadius, ballX+ballRadius, ballY+ballRadius);
  paint.setColor(Color.LTGRAY);
  // canvas.drawImage(R.drawable.background_image); (Ps: I know there is no function such as drawImage)"
  canvas.drawOval(ballBounds, paint);}
Run Code Online (Sandbox Code Playgroud)

android view background-image

2
推荐指数
1
解决办法
2万
查看次数