相关疑难解决方法(0)

将图像调整到ImageView中,保持纵横比,然后将ImageView调整为图像尺寸?

如何将随机大小的图像拟合到ImageView
什么时候:

  • 最初ImageView尺寸为250dp*250dp
  • 图像的较大尺寸应按比例放大/缩小至250dp
  • 图像应保持其纵横比
  • ImageView缩放后,尺寸应与缩放图像的尺寸相匹配

例如,对于100*150的图像,图像ImageView应为166*250.
例如,对于150*100的图像,图像ImageView应为250*166.

如果我将界限设置为

<ImageView
    android:id="@+id/picture"
    android:layout_width="250dp"
    android:layout_height="250dp"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="20dp"
    android:adjustViewBounds="true" />
Run Code Online (Sandbox Code Playgroud)

图像适合在ImageView,但ImageView总是250dp*250dp.

android scale imageview

153
推荐指数
10
解决办法
27万
查看次数

Android:旋转整个布局

我需要能够动态旋转整个布局(点击按钮).

我能够使用例如旋转布局.layout.setRotation(270.0f).问题是,在旋转之后,布局heightwidth其父级不匹配.

我试过反转height,width像这样,

RelativeLayout layout = (RelativeLayout)findViewById(R.id.rootLayout);
LayoutParams layoutParams = layout.getLayoutParams();
int height = layout.getHeight();
int width = layout.getWidth();
layoutParams.height = width;
layoutParams.width = height;
Run Code Online (Sandbox Code Playgroud)

什么都不做.

我正在努力sdk 14.

下面的第一张图片是应用程序启动时.第二个,轮换后.我想填补黑色的"空间".任何帮助,将不胜感激.

下面的图像仅显示布局中的按钮.然而,实际上,布局要复杂得多.我想要实现的是"假装"景观视图.

开始时 轮换后

编辑:更改图像和添加说明.

android rotation android-layout

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

如何在使用setRotation后刷新linearLayout中的match_parent?

我有几个嵌套的布局,我试图在代码中按需旋转90度.我已经把setRotation的一部分工作得很好,但不幸的是,事情并没有通过轮换来调整.这些元素的宽度设置为match_parent,旋转后它仍然匹配父宽度,而不是它应匹配的父高度.

XML

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="link.basiclifecounter.LifeCounter"
    android:background="#CC00CC">

    <LinearLayout
        android:id="@+id/topPlayers"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="vertical"
        android:background="#CC0000">

        <RelativeLayout
            android:id="@+id/p3"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

        **A bunch of stuff in here**

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/p2"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

        **A bunch of stuff in here**

        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottomPlayer"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:background="#00CC00">

        <RelativeLayout
            android:id="@+id/p1"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

        **A bunch of stuff in here**

        </RelativeLayout>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

旋转Java代码

view.findViewById(R.id.topPlayers).setRotation(90); //Rotate the entire top box
view.findViewById(R.id.p3).setRotation(180); //Flip one side so both …
Run Code Online (Sandbox Code Playgroud)

android rotation android-layout android-xml android-layout-weight

9
推荐指数
1
解决办法
1205
查看次数