【问题标题】:Layout does not align to center of the parent view布局未与父视图的中心对齐
【发布时间】:2015-04-03 21:43:17
【问题描述】:


我试图用不同颜色将两个线性布局中间的圆形图像对齐,但是由于某种原因,视图未与中心对齐
但坚持向左,在它下面我想放置一个片段。有什么帮助吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dip"
                android:layout_weight="1"
                android:background="#1b96d9"
                android:orientation="vertical" >
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#e6e6e6"
                android:orientation="vertical" >
            </LinearLayout>
        </LinearLayout>

        <com.mikhaellopez.circularimageview.CircularImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            android:gravity="center"
            android:src="@drawable/doge"
            app:border_color="#EEEEEE"
            app:border_width="4dp"
            app:shadow="true" />

    </FrameLayout>

    <LinearLayout
        android:id="@+id/calendarCard1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="7"
        android:background="#e6e6e6" />

</LinearLayout>

【问题讨论】:

    标签: android android-view android-framelayout


    【解决方案1】:

    为什么不使用相对布局而不是这么多嵌套的线性布局。使用相对布局既简单又高效。检查此http://www.mkyong.com/android/android-relativelayout-example/ 以了解相关布局

    【讨论】:

    • 因为使用相对布局也行不通,而且您不能使用相对布局创建“权重依赖”视图,而只能使用线性布局。
    【解决方案2】:

    您的圆形图像布局与LinearLayout 一起位于FrameLayout 内。 FrameLayout 基本上是把它所有的孩子都放在一个上面。

    【讨论】:

    • 不正确将“com.mikhaellopez.circularimageview.CircularImageView”替换为常规ImageView,您会看到它放在顶部的中间。
    猜你喜欢
    • 2017-01-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2018-06-25
    • 2019-04-10
    • 1970-01-01
    • 2021-01-27
    • 2014-02-02
    相关资源
    最近更新 更多