<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<com.example.root.howold.MyRing
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
我也尝试设置gravity和layout_gravity,但它们实际上不起作用。
如何在布局中使 MyRing(我的自定义 View )居中?
最佳答案
Try this:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.example.root.howold.MyRing
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
关于Android-如何在 LinearLayout 中将我的自定义 View 居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31869660/