2013-12-05 2 views
1

Я пытаюсь использовать XML для создания пользовательского интерфейса, который выглядит следующим образом.Android - Как создать строки между linearlayouts

Кнопка «Синий галочка» и «Текстовое изображение» выровнены с LinearLayout, расположенным вертикально, поэтому в Relative Layout имеется в общей сложности 3 LinearLayouts. Теперь мне нужно добавить строку, которая находится между каждой кнопкой тика, с выравниванием, которое выглядит так.

изображение выглядит следующим образом:

Image UI

Что раскладка я могу идти об использовании для достижения этой цели?

Это мой текущий код: (РАСТВОР)

Я изменил свое решение, основанное на условии решения @Piyush Гупты! Спасибо всем за помощь!

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="20dp" > 

     <LinearLayout 
      android:id="@+id/linearlayout1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:orientation="horizontal" 
      android:weightSum="3" > 

      <ImageButton 
       android:id="@+id/button01" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:background="@drawable/button" /> 

      <Button 
       android:id="@+id/button1" 
       android:layout_width="wrap_content" 
       android:layout_height="1dp" 
       android:layout_weight="1" 
       android:background="#000" 
       android:src="@android:color/transparent" /> 

      <ImageButton 
       android:id="@+id/button02" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:background="@drawable/button" /> 

      <Button 
       android:id="@+id/button2" 
       android:layout_width="wrap_content" 
       android:layout_height="1dp" 
       android:layout_weight="1" 
       android:background="#000" 
       android:src="@android:color/transparent" /> 

      <ImageButton 
       android:id="@+id/button03" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:background="@drawable/button" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/linearlayout2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/linearlayout1" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:gravity="left" 
       android:text="TextView" /> 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:gravity="center" 
       android:text="TextView" /> 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:gravity="right" 
       android:text="TextView" /> 
     </LinearLayout> 
    </RelativeLayout> 

ответ

1

Используйте этот один:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/custom_toast_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#F14E23" 
    android:orientation="vertical" > 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal" > 

    <ImageButton 
     android:id="@+id/button01" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="@drawable/ic_launcher" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="1dp" 
     android:layout_gravity="center" 
     android:background="#000" 
     android:src="@android:color/transparent" /> 

    <ImageButton 
     android:id="@+id/button02" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="@drawable/ic_launcher" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="1dp" 
     android:layout_gravity="center" 
     android:background="#000" 
     android:src="@android:color/transparent" /> 

    <ImageButton 
     android:id="@+id/button03" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="@drawable/ic_launcher" /> 
</LinearLayout> 

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

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="TextView" /> 
</LinearLayout> 

</LinearLayout> 
+0

Спасибо за помощь! – cokeby190

0

Вы можете использовать представление, чтобы показать этот вид линии. показать представление между линейными макетами и использовать атрибут android:layout_toRightOf="", чтобы сохранить компоновку организованной.

<View android:layout_width="fill_parent" 
     android:background="@color/black" 
     android:layout_height="1dip" /> 
+0

Да, я могу создать линию, которую я просто не знаю, как установить ее между кнопками и центрировать ее по вертикали. Линии также должны иметь динамическую ширину, так как она также должна масштабироваться для размещения на планшете. – cokeby190

0
<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_margin="20dp" > 

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

     <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 

     <ImageButton 
      android:id="@+id/button01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="@android:color/transparent" 
      android:src="@drawable/button" /> 

      <View android:layout_width="60dp" 
      android:background="@color/black" 
      android:layout_height="1dip" 
      android:layout_gravity="center_vertical" 
      /> 

     </LinearLayout> 

     <TextView 
      android:id="@+id/TextView02" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_centerHorizontal="true" > 

     <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 

     <View android:layout_width="60dp" 
     android:background="@color/black" 
     android:layout_height="1dip" 
     android:layout_gravity="center_vertical" 
     /> 

     <ImageButton 
      android:id="@+id/button02" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="@android:color/transparent" 
      android:src="@drawable/button" /> 

      <View android:layout_width="60dp" 
      android:background="@color/black" 
      android:layout_height="1dip" 
      android:layout_gravity="center_vertical" 
      /> 

     </LinearLayout> 

     <TextView 
      android:id="@+id/TextView02" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:orientation="vertical" > 

     <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 

     <View android:layout_width="60dp" 
      android:background="@color/black" 
      android:layout_height="1dip" 
      android:layout_gravity="center_vertical" 
      /> 

     <ImageButton 
      android:id="@+id/button03" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:background="@android:color/transparent" 
      android:src="@drawable/button" /> 

      </LinearLayout> 

     <TextView 
      android:id="@+id/TextView02" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

    </LinearLayout> 

</RelativeLayout> 
+0

Спасибо за образец! Однако теперь это выглядит так ... http://cl.ly/image/0K0U1p0z3o0a Все еще не то, что я надеюсь достичь, я хочу, чтобы линия касалась кнопок, и чтобы линия была центрирована по вертикали внутри кнопки слой, а также не включен TextView. – cokeby190

+0

@cokeby Я изменил код Попробуй это и дайте мне знать – Syn3sthete

+0

Привет, Хари, я пробовал, но он по-прежнему выглядит странно, поскольку линия прилипает к левой стороне кнопки и отделяется от кнопки справа ... – cokeby190

0

Для вашего требования попробовать нижеприведенный код в XML-файле, где когда-либо вам требуется. Это создаст для вас линию.

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="2dp" 
     android:layout_marginBottom="2dp" 
     android:background="@color/black" > 
    </LinearLayout> 

Надеясь, что U может управлять линейной компоновкой «вес».

1

Замените ваш xml следующим кодом. вы можете настроить вес согласно вашим требованиям.

<LinearLayout 
    android:id="@+id/ll1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:weightSum="10" 
    android:orientation="horizontal" > 

    <ImageButton 
     android:id="@+id/button01" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:background="@android:color/transparent" 
     android:src="@drawable/ic_add" /> 

    <View 
     android:layout_width="0dp" 
     android:layout_height="1dp" 
     android:layout_gravity="center" 
     android:layout_weight="2" 
     android:background="@android:color/black" /> 

    <ImageButton 
     android:id="@+id/button02" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:background="@android:color/transparent" 
     android:src="@drawable/ic_add" /> 

    <View 
     android:layout_width="0dp" 
     android:layout_height="1dp" 
     android:layout_gravity="center" 
     android:layout_weight="2" 
     android:background="@android:color/black" /> 

    <ImageButton 
     android:id="@+id/button03" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:background="@android:color/transparent" 
     android:src="@drawable/ic_add" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/ll2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:weightSum="10" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/TextView01" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:layout_weight="2" 
     android:text="TextView" /> 

    <View 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="2" /> 

    <TextView 
     android:id="@+id/TextView02" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:layout_weight="2" 
     android:text="TextView" /> 

    <View 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="2" /> 

    <TextView 
     android:id="@+id/TextView03" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:layout_weight="2" 
     android:text="TextView" /> 
</LinearLayout> 

Надеется, что это поможет.

+0

Спасибо за помощь!Это также работает, но между линиями и кнопками есть разрыв. Но для другой реализации, которая требует этой реализации, также может быть полезно! – cokeby190

Смежные вопросы