PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 26, 2022

[FIXED] How to not crop ImageView inside a LinearLayout?

 July 26, 2022     android, android-image, crop     No comments   

Issue

Hi, I'm trying to make something like this

what i want

And this is what I get

enter image description here

This is the xml

    <?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:layout_width="180dp"
        android:layout_height="match_parent"
        android:layout_marginHorizontal="10dp">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/category_item_background"
            android:clickable="true"
            android:focusable="true"
            android:layout_marginTop="50dp"
            android:orientation="vertical"
            android:paddingBottom="20dp">

        <ImageView
                android:id="@+id/planetImage"
                android:layout_marginTop="-50dp"
                android:layout_gravity="center_horizontal"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:src="@drawable/earth_transparent"
                />

        <TextView
                android:id="@+id/planetName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:textColor="@color/white"
                android:text="Mars"
                android:fontFamily="@font/assistant_extrabold"
                android:textSize="30dp"/>

        <TextView
                android:id="@+id/planetViews"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:fontFamily="@font/assistant_extrabold"
                android:text="155 views"/>

    </LinearLayout>


</LinearLayout>

The image is cropped and I can't figure out how to predict that. I don't care about colour difference right now, I just want to set something, so it doesn't crop the image.


Solution

just put imageview outside

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="180dp"
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="10dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:background="@drawable/category_item_background"
        android:clickable="true"
        android:focusable="true"
        android:orientation="vertical"
        android:paddingBottom="20dp">

        <TextView
            android:id="@+id/planetName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="70dp"
            android:fontFamily="@font/assistant_extrabold"
            android:gravity="center_horizontal"
            android:text="Mars"
            android:textColor="@color/white"
            android:textSize="30dp" />

        <TextView
            android:id="@+id/planetViews"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/assistant_extrabold"
            android:gravity="center_horizontal"
            android:text="155 views" />

    </LinearLayout>

    <ImageView
        android:id="@+id/planetImage"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        android:background="@color/black"
        android:src="@drawable/earth_transparent" />

</RelativeLayout>


Answered By - Yura
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing