FORUMS

Setting position of ImageView according to an image (dynamic with screen sizes)

1 posts
Thanks Meter: 0
 
By MarkS419, Junior Member on 14th May 2020, 01:46 PM
Post Reply Email Thread
Hello,
I learned that to make a bitmap image clickable, I need to assign it to ImageView. However, I am failing to set the position correctly so that it is dynamic with every screensize. It really is not possible to let ImageView locate the bitmap image on the screen and act upon that? I tried so many things but the best I have now is that ImageView creates another image of my button and when I manually change its position, it does not scale properly with other screen sizes.

For example my AdView (visible in xml) scales correctly with other screens but I could not apply the same principles with my button.

I would prefer if ImageView would just take the location of drawn bitmap button on screen but if this is not possible, could you guys please provide me with some example codes of how to correctly set the button generated by ImageView? So that I can move it to desired location and have it the same across different screen sizes.

I HAVE TRIED:

Changing position manually in SurfaceView - doesnt scale properly

Implement app:layout_widthPercent="50%" etc. - doesnt work for me

Implement app:layout_constraintBottom etc. - doesnt work for me


activity_main.xml:

<com.markS.flappykillercrow.GameManager
android:id="@+id/gameManager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/image_button_android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"

android:src="@drawable/playbutton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>


Thank you very much in advance, this would save my day!
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes