Android + Какой макет вы бы предложили? - PullRequest
2 голосов
/ 27 сентября 2011

Я выкладываю строку для использования в ListView, и мне нужна небольшая помощь.Строка будет выглядеть следующим образом:

enter image description here

Ниже приведено то, что у меня есть, выделение bg не отображается, и текст не выравнивается по центру (прилипает к верху).).

<?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_height="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>

Ответы [ 3 ]

1 голос
/ 27 сентября 2011

Я бы использовал только один RelativeLayout.Это позволит избежать использования различных макетов и упростить размещение компонентов на экране.

edit: Это решение работает, но я не знаю, является ли оно лучшим:

<?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>
0 голосов
/ 24 сентября 2013

enter image description here Проверьте это

![<?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 голосов
/ 27 сентября 2011

Посмотрите на эти уроки, вы можете выбрать, какой макет лучше. Каждый макет имеет свои достоинства и недостатки. Только тот, который макет не является лучшим в Android, но в большинстве случаев Relative layout прост в использовании, потому что он перешел на легкий в любом месте пользовательского интерфейса.

точно так же, как ваши проблемы со спичками, учебные пособия

http://android -developers.blogspot.com / 2009/02 / Android-макета фокусы-1.html

Вы можете увидеть больше макета в developer.android.con. который должен учиться более простым способом. здесь некоторые Best links вы можете увидеть различные макеты.

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-макета учебник /

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...