【问题标题】:Need xml layout for the below screen下面的屏幕需要xml布局
【发布时间】:2013-07-21 03:17:07
【问题描述】:

我正在创建一个带有标题“帐户信息”的布局的页面(参考图像)。后跟一个表格,我需要在从服务器获取后动态填充表格,但无法这样做。以下是 .xml 文件并附上图片:

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@layout/header_gradient" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_weight="0.20"
            android:gravity="center_horizontal"
            android:padding="15dp"
            android:text="@string/my_account_header_text"
            android:textColor="#ffffff"
            android:textSize="24sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffffff" >

        <RelativeLayout
            android:id="@+id/my_activity_layout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#ffffff" >

            <TextView
                android:id="@+id/my_acc_component"
                android:layout_width="158dp"
                android:layout_height="wrap_content"
                android:text="@string/my_account_component"
                android:textColor="#372c24"
                android:textSize="@dimen/login_credentials_txt" />

            <TextView
                android:id="@+id/my_acc_details"
                android:layout_width="158dp"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/my_acc_component"
                android:text="@string/my_account_details"
                android:textColor="#372c24"
                android:textSize="@dimen/login_credentials_txt" />
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

【问题讨论】:

  • 到底是什么问题?另外,您的图片链接似乎丢失了...

标签: android layout android-tablelayout dynamic-loading


【解决方案1】:

这可能不是您的问题,因为我还不知道问题出在哪里,但我发现了一个问题。当在 LinearLayoutvertical orientation 中使用 weight 时,您的 height 应该是 0dp。同样,如果它是horizontal orientation,那么width 应该是0dp。因此,例如,您可以将 layouts 更改为

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="#ffffff" >

<RelativeLayout
        android:id="@+id/my_activity_layout"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffffff" >

另外,这绝对不是您的问题,但 fill_parent 已被弃用,应使用 match_parent 代替。

【讨论】:

    【解决方案2】:
    *Actually, there is a problem with the weight property... if you are working with weight then you better use weight_sum property in the LinearLayout and give your textView or other view an percentage depending on your giver weight_sum value in the parent layout...
    However,I think what you are looking for is something like this:*  
    
    
    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center|top"
     <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/header"
    android:background="@drawable/image" // if you want your title/header to be upon the image. Or just create another ImageView for that image
    />
    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="100"
    android:orientation="horizontal"
    >
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:margin_Top="50dp"
    android:weight="50"
    android:id="@+id/my_acc_component"
    android:text="your text"
    android:textSize="your Size"
    />
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:margin_Top="50dp"
    android:weight="50"
    android:id="@+id/my_acc_details"
    android:text="your text"
    android:textSize="your Size"
    />
    </LinearLayout>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多