简体   繁体   English

Android-修复图标的位置

[英]Android - Fix Position of Icon

I have a two RelativeLayouts which each contains an ImageView and a TextView . 我有两个RelativeLayouts ,每个都包含一个ImageView和一个TextView On clicking on a TextView , the size of the TextView increases and the size of the other Textview decreases. 在点击一个TextView ,的大小TextView增加,其他的大小Textview降低。 However, the position of the ImageView also changes.I want the Image to be fixed irrespective of the size of the textview . 但是, ImageView的位置也会发生变化。我希望Image固定不分textview的大小。 What changes should be made? 应该进行哪些更改?

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/bb_bottom_bar_outer_container"
             android:layout_width="match_parent"
             android:layout_height="60dp"
             android:background="@drawable/float_common"
             android:clickable="true">

    <LinearLayout
        android:id="@+id/btn_updatenow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_grey"
        android:orientation="horizontal"
        android:weightSum="3">

        <RelativeLayout
            android:id="@+id/float_layout_home"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:paddingTop="2dp">

            <ImageView
                android:id="@+id/float_image_home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="@dimen/margin_6"
                android:background="@drawable/float_home_onclick"
            />

            <TextView
                android:id="@+id/float_text_home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:paddingBottom="@dimen/margin_10"
                android:text="@string/home"
                android:textColor="@color/text_mid_grey"
            />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/float_layout_offers"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical"
            android:paddingTop="2dp">

            <ImageView
                android:id="@+id/float_offers"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="@dimen/margin_6"
            />

            <TextView
                android:id="@+id/float_text_offers"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:paddingBottom="@dimen/margin_10"
                android:text="@string/offers"
                android:textColor="@color/text_mid_grey"
            />
        </RelativeLayout>
    </LinearLayout>

</FrameLayout>

Try by setting your 2 RelativeLayout s android:layout_width as 0dp. 尝试将2个RelativeLayout的android:layout_width设置为0dp。

When Linearlayout contains many views inside and set layout_weight as 1 layout_height or layout_width = 0dp is used, in order to take equal space for both views. 当Linearlayout内部包含许多视图并且将layout_weight设置为1时,将使用layout_height或layout_width = 0dp,以便为两个视图占用相等的空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM