简体   繁体   English

在 ImageView - CS50 Pokedex Android 内对齐 Bitmap 图像

[英]Align Bitmap Image inside ImageView - CS50 Pokedex Android

I have been working on CS50 and now I am tracking android.我一直在研究 CS50,现在我正在跟踪 android。 I almost finished my PSet Pokedex, but small thing is bothering me.我几乎完成了我的 PSet Pokedex,但有小事困扰着我。

I am trying to align bitmap image on top of ImageView, but I could not do it.我试图在 ImageView 上对齐 bitmap 图像,但我做不到。 Could you please help me?请你帮助我好吗? I tried "scaletype", "layout_gravitiy" etc. But it does not seem to work.我尝试了“scaletype”、“layout_gravitiy”等。但它似乎不起作用。 I want image to be just below description stating that this should be changed by the java code.我希望图像在说明下方,说明这应该由 java 代码更改。 Please see current view here请在此处查看当前视图

    <?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>

Welcome to StackOverFlow !欢迎来到 StackOverFlow!

If there is no special requirement than no need to use match_parent inside ImageView.如果没有特殊要求,则无需在 ImageView 中使用match_parent You can do following adjustment-您可以进行以下调整-

<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">

    ..............

    <ImageView
        android:id="@+id/pokemon_avatar"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

Happy coding !快乐编码!

sorry.对不起。 I was roasting snow in a furnace.我在炉子里烤雪。 I found out that actually source image is one to blame.我发现实际上源图像是罪魁祸首。 Image size does not wrap the content but it has extra space around content.图像大小不包含内容,但它在内容周围有额外的空间。 This is the reason when it is enlarged, there is space between text and image.这就是放大时,文字和图像之间有空间的原因。 图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM