Setting of ImageView’s gravity to the center in android programmatically
Try this LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(width, height); layoutParams.gravity=Gravity.CENTER; ImageIcons[i].setLayoutParams(layoutParams);
Try this LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(width, height); layoutParams.gravity=Gravity.CENTER; ImageIcons[i].setLayoutParams(layoutParams);
Set the scaleType to fitStart in your XML: <ImageView android:id=”@+id/ivMap” android:layout_width=”match_parent” android:layout_height=”match_parent” android:scaleType=”fitStart” > </ImageView>
87element, I believe you intended to use layout_gravity you are only using gravity?? Yes, you can combined two of these layout_gravity attributes together with the ‘|’ as mentioned in the documentation: http://developer.android.com/reference/android/R.attr.html#layout_gravity But even using layout_gravity instead of just gravity (as adamp stated in his comment), the settings you are trying to combine don’t make … Read more
We can align a view in center of the FrameLayout by setting the layout_gravity of the child view. In XML: android:layout_gravity=”center” In Java code: FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER; Note: use FrameLayout.LayoutParams not the others existing LayoutParams
Tab gravity only effects MODE_FIXED. One possible solution is to set your layout_width to wrap_content and layout_gravity to center_horizontal: <android.support.design.widget.TabLayout android:id=”@+id/sliding_tabs” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”center_horizontal” app:tabMode=”scrollable” /> If the tabs are smaller than the screen width, the TabLayout itself will also be smaller and it will be centered because of the gravity. If the tabs are … Read more
labelTV.setGravity(Gravity.CENTER | Gravity.BOTTOM); Kotlin version (thanks to Thommy) labelTV.gravity = Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM Also, are you talking about gravity or about layout_gravity? The latter won’t work in a RelativeLayout.