使用xml创建自定义gridView项

时间:2013-09-10 13:36:01

标签: android xml android-layout relativelayout android-gridview

我正在使用以下RelativeLayoutGridView

中创建项目
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp"
    android:background="@drawable/border">

    <ImageView
        android:id="@+id/icon_service"
        android:layout_width="290dp"
        android:layout_height="268dp"        
        android:layout_alignParentTop="true"
        android:src="@drawable/icon"
        android:layout_centerHorizontal="true">
    </ImageView>

    <TextView
        android:text="My text"
        android:layout_height="80dp"
        android:id="@+id/service"
        android:layout_width="wrap_content"
        android:layout_below="@+id/icon_service"
        android:layout_marginTop="2dp"
        android:layout_centerHorizontal="true"
        android:gravity="top|center"
        android:textSize="24sp"
        android:textColor="#ff0000"
        android:ellipsize="marquee">
    </TextView>
</RelativeLayout>

给了我这个:

enter image description here

相反,我想要的是:

enter image description here

2 个答案:

答案 0 :(得分:1)

您的图片视图位于正确的位置, 下面,而不是直接放置textview .. 将一个线性布局放置在水平方向上, 并使这个LinearLayout,TextView和ImageView的两个孩子...... 多数民众赞成......

答案 1 :(得分:0)

您只提供一个ImageView,并期望两个图像视图看到您的代码..为了获得您想要的结果采取一个线性布局,给它wightsum = 10和方向垂直,并采取一个图像和另一个linerlayout在this.give权重imageview 7和linearlayout 3 ..然后设置第二个linearlayout weightsum等于6并在第二个布局中取一个textview和一个imageview并将textview权重设置为4并且imageview等于2 ..如果不相等则查看结果对你的期望...定制权重......如

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="10"
    android:orientation="vertical">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="7"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:weightSum="6"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="4"/>
        <ImageView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"/>
    </LinearLayout>
</LinearLayout>
相关问题