How can I achieve this shape without rotation? - android-layout

I want to achieve this shape which is clubhouse's profile ImageView shape
clubhouse profile example
but this shape is is not exactly a square with rounded corners it is more like a square with rounded corners AND curved sides as well
My xml ShapeableImageView:
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/profilePictureShapeableImageView"
android:layout_width="50dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="1:1"
app:shapeAppearanceOverlay="#style/ShapeAppearanceOverlay.App.CornerSize50Percent"
android:src="#drawable/ic_profile1"
android:scaleType="centerCrop"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
My style for its corners:
<style name="ShapeAppearanceOverlay.App.CornerSize50Percent" parent="">
<item name="cornerSize">43%</item>
</style>
I have tried many times to make its corners round with many weird ways but none of them worked I also tried to make a layout like
Custom shaped Linearlayout with curved side in android
but no result in my case.
The closest result to the original I have achieved until now is this attempt
this was achieved by increasing cornerSize to 55% and by setting rotation 45 to ShapeableImageView
with this way I have created some other problems which are out of topic.

Related

is possible to make a button shape like a cross?

is possible to have a single button that has a shape of a cross and that it is clickable only in the visible part?
defining curves with coordinates or setting an image with this cross and somehow setting that where the image is transparent, it must not be clickable ..
if yes, with witch method?
I tried to search online but apart from the radus (which in this case I don't need), I didn't find any documentation
yes you can add your button as ImageButton and put your shap in that button
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:scaleType="fitXY"
android:background="#color/transparent"
android:src="#drawable/ic_close_image"/>

Motion Layout: How to change view visibility on last frame

I am using motion layout in android studio to make a page that scrolls and looks kind of like Twitter. I want to set the visibility of the layout that contains the name to GONE at the very end of the animation.
Normally, if you set it to gone at the end it gradually disappears through the animation. But I want it to dissaper suddenly.
I am using motion layout and kind of understand key frames, but how do you do it with visibility?
Thanks.
I would like to leave an answer here, in case anybody encounter this like me:
Animating alpha and controlling its frames does the job, but the case when you want a view to be actually gone from the layout, I needed to make use of visibility for that.
I wrote it in another post, but keep it here for ease of read:
A background view, that should be gone when alpha is 0, and once alpha is getting greater than 0 just stay visible all the time, but motion shouldn't animate the visibility all.
Configure KeyFrameSet for visibility, so at frame 0 visibility is gone, and starting from frame 1 visibility is visible.
Set required visibility of the background view in both #id/start and #id/end constraint sets.
Set visibiltyMode as ignore for the background view in both #id/start and #id/end constraint sets, so motion will ignore animating this attribute for the background view.
<MotionScene
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
android:id="#+id/transition"
motion:constraintSetEnd="#+id/end"
motion:constraintSetStart="#id/start"
motion:duration="#integer/standard_duration">
<KeyFrameSet>
<KeyAttribute
motion:framePosition="0"
motion:motionTarget="#id/background">
<CustomAttribute
motion:attributeName="visibility"
motion:customIntegerValue="8" />
</KeyAttribute>
<KeyAttribute
motion:framePosition="1"
motion:motionTarget="#id/background">
<CustomAttribute
motion:attributeName="visibility"
motion:customIntegerValue="0" />
</KeyAttribute>
</KeyFrameSet>
</Transition>
<ConstraintSet android:id="#+id/start">
...
<Constraint
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.5"
android:visibility="gone"
motion:visibilityMode="ignore"
/>
</ConstraintSet>
<ConstraintSet android:id="#+id/end">
...
<Constraint
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.5"
android:visibility="visible"
motion:visibilityMode="ignore"
/>
</ConstraintSet>
</MotionScene>
Btw, the corresponding integer values for visibility are:
Visible = 0
Invisible = 4
Gone = 8
You can set the alpha value for the 0,99 and 100th frame positions as shown below.
<KeyFrameSet>
<KeyAttribute
android:alpha="1"
motion:framePosition="0"
motion:motionTarget="#id/textView" />
<KeyAttribute
android:alpha="1"
motion:framePosition="99"
motion:motionTarget="#id/textView" />
<KeyAttribute
android:alpha="0"
motion:framePosition="100"
motion:motionTarget="#id/textView" />
</KeyFrameSet>
By this way, the textview will fade out from 99 to 100th frame, but it will look as it disappeared almost suddenly.

Adding Layout Weight dynamically

For my project I want 30 images in my page, and I want to arrange them in such a way that there are 3 images in one horizontal linear layout.
Since I cannot use density pixels as it may look different on different divices, I want to use layout_weights. The way we write in our XML files :
<ImageButton
android:id="#+id/my_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
**android:layout_weight="0.33"**
android:background="#android:color/transparent"
android:src="#drawable/ic_launcher" />
I want to know what will be the Exact Equivalent of the XML code in Java Language..
You can set the weight using the LayoutParams of your view (the last param)
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, 1.0f);
myView.setLayoutParams(params);

what element type and layout for should I use for app landing page navigation buttons?

I'm pretty new to Android Development, i'm following some Youtube tutorials currently. I'd like to create a basic mobile tourist application, but i'm stuck as to how to create the main menu layout.
Each Favorite 1 - 3, and Options 1 - 9 should be icons. (I'm not sure which form element should be used for this).
QuestionHow can I create the favorite, and option icons in the layout.xml file, what element is best suited, and what layout(s) should I use?
In HTML, i'd create a table with 3 columns, 4 rows and set the table width and height to be 100%, and make the td valign and align central.
Here you could make horizontal linearLayouts of vertical LineraLayouts of Image+TextView pairs.
The second range linear layouts would have
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
Inside second range layouts you could use for image and text/view:
...for images:
android:layout_width="match_parent"
android:layout_weight="3"
android:layout_height="0dp"
... for texts
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
And the screen is nicely divided.

How can I get ImageView to scale an image and align top right?

I've spent 3 hours trying to get this to work without success so heopfully someone here can help.
I have a FrameLayout that is being loaded via inflate from an XML file and in it I have the following layout:
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/element_image"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:scaleType="fitStart"
android:background="#888888" >
</ImageView>
<Button android:id="#+id/element_button"
style="#style/Button"
android:layout_gravity="right"
android:text="#string/element_button_label"
/>
</LinearLayout>
I have an image loaded from a BLOB which I want to display in this ImageView. In the GalleryAdaptor I load the image like this:
ImageView image = (ImageView) v.findViewById(R.id.element_image);
byte [] bitmapData = cursor.getBlob(4);
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
image.setImageBitmap(bitmap);
When I use android:scaleType="fitStart" in the layout above the image is not scaled to the height or width of the ImageView but is about a third of it's width (which I can see from the grey background I have given it) and is centered.
If I use android:scaleType="fitXY" the image height is scaled but the width is not. Again the image is centered.
Can someone give me some pointers on:
How to get the image to scale both height and width wise
How to align the image top right
Answering my own question here - but looks like this was just an issue with the source image resolution. Android (2.2 at least) does not seem to want to scale these images up when fitStart or fitEnd is used - but when fitXY is used it does scale them.

Resources