首页 > 解决方案 > 在 ImageView 中对齐位图图像 - CS50 Pokedex Android

问题描述

我一直在研究 CS50,现在我正在跟踪 android。我几乎完成了我的 PSet Pokedex,但有小事困扰着我。

我试图在 ImageView 上对齐位图图像,但我做不到。请你帮助我好吗?我尝试了“scaletype”、“layout_gravitiy”等。但它似乎不起作用。我希望图像正好在说明下方,说明这应该由 java 代码更改。 请在此处查看当前视图

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".PokemonActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pokemon_name"
        android:textAlignment="center"
        android:textSize="18dp"
        android:textStyle="bold"
        android:paddingTop="10dp" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pokemon_number"
        android:textAlignment="center"
        android:textSize="16dp"
        android:paddingTop="5dp" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pokemon_type1"
        android:textAlignment="center"
        android:textSize="16dp"
        android:paddingTop="5dp" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pokemon_type2"
        android:textAlignment="center"
        android:textSize="16dp"
        android:paddingTop="5dp" />

    <Button
        android:id="@+id/pokemon_button_catch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:paddingTop="5dp"
        android:textSize="24dp"
        android:onClick="toggleCatch"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pokemon_description"
        android:textAlignment="center"
        android:textSize="16dp"
        android:textStyle="bold|italic"
        android:paddingTop="50dp"
        android:text="This is testing something, this should changed by the java code."/>

    <ImageView
        android:id="@+id/pokemon_avatar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

标签: javaandroidxmlandroid-studiocs50

解决方案


对不起。我在炉子里烤雪。我发现实际上源图像是罪魁祸首。图像大小不包含内容,但它在内容周围有额外的空间。这就是放大时,文字和图像之间有空间的原因。 图片


推荐阅读