开发者

Android + Which layout would you suggest?

开发者 https://www.devze.com 2023-04-08 08:22 出处:网络
I\'m laying out a row for use in a ListView and I need a little help.The row will look like this: Below is what I have so far, the highlight bg is not showing up and the text won\'t align center (s

I'm laying out a row for use in a ListView and I need a little help. The row will look like this:

Android + Which layout would you suggest?

Below is what I have so far, the highlight bg is not showing up and the text won't align center (sticks to the top).

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/rl0"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:padding="0dp"
  android:layout_margin="0dp"
  android:background="@color/grey">
  <!-- shine -->
  <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
      android:id="@+id/imgShine"
      android:background="@color/shine"
      android:layout_height="0dp"
      android:layout_width="fill_parent"
      android:layout_weight="1" />
    <View
      android:layout_height="0dp"
      android:layout_width="fill_parent"
      android:layout_weight="1" />
  </LinearLayout>
  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:id="@+id/ll"
    android:layout_gravity="center_vertical">
    <!-- cal graphic -->
    <RelativeLayout
      android:id="@+id/rl1"
      android:layout_width="wrap_content"
      android:layout_he开发者_开发知识库ight="match_parent"
      android:padding="10dp">
      <!-- cal bg -->
      <ImageView
        android:id="@+id/imageView1"
        android:src="@drawable/cal"
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true" />
      <!-- month -->
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tvMonth"
        android:textSize="11sp"
        android:layout_marginLeft="11dp"
        android:layout_marginTop="10dp"
        android:textColor="@drawable/list_cal_selector" />
      <!-- day -->
      <TextView
        android:id="@+id/tvDay"
        android:textSize="23sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvMonth"
        android:layout_marginTop="2dp"
        android:layout_centerHorizontal="true"
        android:textColor="@drawable/list_cal_selector" />
    </RelativeLayout>
    <!-- text and button graphic -->
    <RelativeLayout
      android:id="@+id/rl2"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:gravity="center_vertical"
      android:layout_gravity="center_vertical">
      <!-- team name -->
      <TextView
        android:id="@+id/tvTeam"
        android:textSize="23dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="0dp"
        android:textColor="@drawable/list_text_selector" />
      <TextView
        android:id="@+id/tvTime"
        android:textSize="12sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvTeam"
        android:textColor="@drawable/list_text_selector" />
      <TextView
        android:id="@+id/tvStation"
        android:textSize="12sp"
        android:paddingLeft="12dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvTeam"
        android:layout_toRightOf="@+id/tvTime"
        android:textColor="@drawable/list_text_selector" />
      <!-- add button -->
      <ImageView
        android:id="@+id/imgAddBtn"
        android:src="@drawable/btn"
        android:layout_height="wrap_content"
        android:layout_width="60dp"
        android:scaleType="fitCenter"
        android:layout_centerVertical="true"
        android:adjustViewBounds="true"
        android:layout_alignParentRight="true"
        android:padding="10dp" />
      <!-- divider -->
      <ImageView
        android:id="@+id/imgDivider"
        android:src="@drawable/divider"
        android:layout_height="fill_parent"
        android:layout_width="2dp"
        android:layout_toLeftOf="@id/imgAddBtn"
        android:cropToPadding="false" />
    </RelativeLayout>
  </LinearLayout>
</FrameLayout>


I would use just one RelativeLayout. It will avoid the use of various Layouts and its easier to place componentes on screen.

edit: This solution works, but I don't know if it's the best:

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

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"  >

        <View
            android:layout_width="1dp"
            android:layout_height="0dp"
            android:layout_weight="0.25"/>

        <ImageView
            android:layout_weight="0.5"
            android:layout_height="0dp"
            android:layout_width="50dp"
            android:background="#dedede"/>

        <View
            android:layout_width="1dp"
            android:layout_height="0dp"
            android:layout_weight="0.25"/>
    </LinearLayout>

    <!-- 
    ...
     -->
</RelativeLayout>


Look at this tutorials you can choose which layout is best. Every layout has own merits and demerits. Only one that layout is not best in android but in most cases Relative layout easy to use because it has move to easy any where of UI.

just like your matches problems, tutorials

http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

you can see more layout of in developer.android.con. which has to learn more simply way. here some Best links you can see various layouts.

http://developer.android.com/resources/tutorials/views/hello-relativelayout.html

http://developer.android.com/guide/topics/ui/layout-objects.html

http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-relative-layouts/

http://www.learn-android.com/2010/01/05/android-layout-tutorial/


Android + Which layout would you suggest?

Check this out

![<?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="35dp"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:scaleType="centerInside"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_weight="4"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Row 1" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:text="Row 2" />

            <TextView
                android:layout_marginLeft="10dp"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Row 3" />
        </LinearLayout>
    </LinearLayout>

    <View android:layout_height="match_parent"
        android:layout_width="2dp"
        android:background="#fff"/>
    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:scaleType="centerInside"
        android:src="@drawable/ic_launcher" />

</LinearLayout>
0

精彩评论

暂无评论...
验证码 换一张
取 消