代码之家  ›  专栏  ›  技术社区  ›  sagar suri

android中具有圆形ImageView和textview的自定义行

  •  0
  • sagar suri  · 技术社区  · 8 年前

    RecyclerView . 这是我的自定义行布局:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:layout_margin="5dp"
        android:background="#00000000">
    
        <FrameLayout
            android:id="@+id/customLevelLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <ImageView
                    android:id="@+id/levelImage"
                    android:layout_width="160dp"
                    android:layout_height="160dp"
                    android:layout_above="@+id/gameText"
                    android:layout_centerInParent="true"
                    android:scaleType="fitXY"
                    android:src="@drawable/circular_background" />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:text="1"
                    android:textColor="#fff"
                    android:textSize="45sp" />
    
                <TextView
                    android:id="@+id/gameText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="10dp"
                    android:gravity="center"
                    android:textColor="#000"
                    tools:text="Tracing" />
            </RelativeLayout>
    
            <ProgressBar
                android:id="@+id/gameProgressBar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#fff"
                android:indeterminate="true"
                android:padding="45dp"
                android:visibility="gone" />
        </FrameLayout>
    
        <ImageView
            android:id="@+id/lockImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/lock_background"
            android:padding="45dp"
            android:src="@drawable/lock"
            android:visibility="gone" />
    </RelativeLayout>
    

    它看起来是这样的:

    enter image description here

    问题是,我必须定义自定义行的预定义高度,即 170dp

    1) 如果我在小屏幕或平板设备中打开应用程序。自定义行看起来很难看,即我松开了 ImageView .

    4 回复  |  直到 8 年前
        1
  •  1
  •   KeLiuyue    8 年前

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:background="#00000000">
    
    <FrameLayout
        android:id="@+id/customLevelLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <ImageView
                    android:id="@+id/levelImage"
                    android:layout_width="160dp"
                    android:layout_height="160dp"
                    android:layout_centerInParent="true"
                    android:scaleType="fitXY"
                   android:src="@drawable/circular_background" />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:gravity="center"
                    android:text="1"
                    android:textColor="#fff"
                    android:textSize="45sp"/>
            </RelativeLayout>
    
    
            <TextView
                android:id="@+id/gameText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:gravity="center"
                android:textColor="#000"
                tools:text="Tracing"/>
        </LinearLayout>
    
        <ProgressBar
            android:id="@+id/gameProgressBar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#fff"
            android:indeterminate="true"
            android:padding="45dp"
            android:visibility="gone"/>
    </FrameLayout>
    
    <ImageView
        android:id="@+id/lockImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/lock_background"
        android:padding="45dp"
        android:src="@drawable/lock"
        android:visibility="gone" />
    </RelativeLayout>
    

    enter image description here

        2
  •  1
  •   Upendra Shah    8 年前

    试试这个。您可以使用 Linearlayout RelativeLayout

    <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="#00000000"
        android:orientation="vertical">
    
        <FrameLayout
            android:id="@+id/customLevelLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
    
                    <ImageView
                        android:id="@+id/levelImage"
                        android:layout_width="160dp"
                        android:layout_height="160dp"
                        android:layout_centerInParent="true"
                        android:scaleType="fitXY"
                        android:src="@drawable/circular_background" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:text="1"
                        android:textColor="#fff"
                        android:textSize="45sp" />
    
                </RelativeLayout>
    
                <TextView
                    android:id="@+id/gameText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:layout_margin="10dp"
                    android:gravity="center"
                    android:textColor="#000"
                    tools:text="Tracing" />
            </LinearLayout>
    
            <ProgressBar
                android:id="@+id/gameProgressBar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#fff"
                android:indeterminate="true"
                android:padding="45dp"
                android:visibility="gone" />
        </FrameLayout>
    
        <ImageView
            android:id="@+id/lockImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/lock_background"
            android:padding="45dp"
            android:src="@drawable/lock"
            android:visibility="gone" />
    </LinearLayout>
    
        3
  •  0
  •   Vijay Chaudhary    8 年前

    使用 约束布局 这有助于您通过拖放和添加约束来设置所需的图像

        4
  •  0
  •   user2851150    8 年前

    支持多屏。首先,你必须通过这个链接 enter link description here

    一旦你解决了第一个问题,第二个问题也会得到解决