2017-07-13 20 views
1

この写真のようなUIを作成したいと思ったが、固定レイアウトでは動作しない相対レイアウトで背景を表示しようとしたが、下のUIで左下に赤い縦線を作成するにはどうすればよいですか?Android XMLで固定高さの縦線を作成するにはどうすればよいですか?

UI,I wanted to create

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="#f5f5f5" 
android:orientation="vertical" 
tools:ignore="MissingPrefix"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#a9382b"> 

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

     <ImageView 
      android:layout_marginLeft="14dp" 
      android:layout_marginTop="14dp" 
      android:layout_marginBottom="14dp" 
      android:layout_marginRight="9dp" 
      android:layout_width="20dp" 
      android:layout_height="20dp" 
      android:src="@drawable/globe"/> 

     <TextView 
      android:layout_marginTop="9dp" 
      android:layout_weight="7" 
      android:layout_marginBottom="9dp" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:textSize="13sp" 
      android:textColor="#b3ffffff" 
      fontPath="fonts/montserrat-medium.ttf" 
      android:letterSpacing="-0.03" 
      android:lineSpacingExtra="2sp" 
      tools:text="Farmer Suicides, Agitations The Indian Agrarian 
    Crisis" 
      /> 

     <LinearLayout 
      android:layout_weight="3" 
      android:layout_width="0dp" 
      android:layout_marginRight="16dp" 
      android:layout_height="wrap_content"> 
     <Button 
      android:layout_width="87dp" 
      android:layout_height="32dp" 
      android:background="@drawable/button" 
      android:text="FOLLOW" 
      android:textColor="#FFFFFF" 
      fontPath="fonts/montserrat-medium.ttf" 
      android:layout_marginTop="8dp" 
      android:layout_marginBottom="8dp" 
      android:layout_marginLeft="12dp" 
      android:textSize="12sp" 
      android:lineSpacingExtra="0sp" 
      android:gravity="center_horizontal||center_vertical" 
      /> 
     </LinearLayout> 



    </LinearLayout> 



</RelativeLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="0dp" 
    android:layout_marginTop="17dp" 
    android:layout_marginLeft="15dp"> 

    <LinearLayout 
     android:layout_gravity="center" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_marginRight="15dp"> 

    <ImageView 
     android:layout_gravity="center" 
     android:layout_width="10dp" 
     android:layout_height="10dp" 
     android:background="@drawable/ic_radio_button_unchecked_black_24dp" 
     /> 


    </LinearLayout> 



<TextView 
    android:layout_gravity="center" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="13sp" 
    android:textColor="#757575" 
    android:letterSpacing="-0.03" 
    android:lineSpacingExtra="0sp" 
    tools:text="8 hours ago" 
    /> 

</LinearLayout> 

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

    <view 
     android:layout_width="2dp" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="19dp" 
     android:background="#a9382b" 
     android:layout_marginRight="19dp"/> 

    <ImageView 
     android:layout_marginTop="10dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="20dp" 
     android:src="@drawable/background_splash" /> 

</LinearLayout> 

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

    <view 
     android:layout_width="2dp" 
     android:layout_alignParentTop="true" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="19dp" 
     android:background="#a9382b" /> 

    <TextView 
     android:id="@+id/seeall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="20dp" 
     android:textColor="#a9382b" 
     android:textSize="11sp" 
     tools:text="SEE ALL" /> 

    <TextView 
     android:id="@+id/articles" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="10dp" 
     android:layout_toLeftOf="@id/seeall" 
     android:textColor="#757575" 
     android:textSize="11sp" 
     tools:text="7 Articles" 

     /> 


</RelativeLayout> 

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

    <View 
     android:layout_width="match_parent" 
     android:layout_height="0.5dp" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="20dp" 
     android:background="#a9382b"/> 

</LinearLayout> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="15dp"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignParentLeft="true" 
     android:layout_centerInParent="true" 
     android:layout_marginRight="15dp"> 


     <ImageView 
      android:layout_gravity="center" 
      android:layout_width="10dp" 
      android:layout_height="10dp" 
      android:background="@drawable/ic_add_circle_outline_black_24dp" 
      /> 

    </LinearLayout> 

    <TextView 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:id="@+id/view_more" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="11sp" 
     android:textColor="#a9382b" 
     android:layout_marginRight="20dp" 
     android:layout_alignParentRight="true" 
     android:gravity="end" 
     tools:text="VIEW FULL STORY" 
     android:layout_marginTop="15dp" 

     /> 




</RelativeLayout> 



</LinearLayout> 
+0

リサイクラービューのカスタム行ファイルですか? – Piyush

+0

'ConstraintLayout'を使い始める –

+1

Viewを使うこともできますし、このライブラリを試してみることもできます。 https://devhub.io/repos/vipulasri-Timeline-View この種の縦線はTimeLine-View – Shekhar

答えて

0

あなたが任意のコードを与えられていないので、あなたは、このような直線を描くことができます:固定の高さの線を描画するためにあなたのxmlファイル内のコード以下

    <View 
        android:layout_width="1dp" 
        android:layout_height="50dp" 
        android:background="#cdcdcd" /> 
+0

[View](https://developer.android.com/reference/android/view/View)で高さ(50dp)を持つ直線の垂直線をコーディングする方法にちょうど答えました。 .html) –

0

を使用し、

<View 
    android:id="@+id/view_vertical_line" 
    android:layout_width="1sp" 
    android:layout_height="500sp" 
    android:layout_marginLeft="15sp" 
    android:background="@color/black" /> 
0

以下のコードを使用して固定高さの縦線を描画できます

次の2つの答え

1で試すことができ

<View 
     android:layout_width="specify thickness in dp" 
     android:layout_height="specify fixed height in dp" 
     android:background="specify color of line"/> 
0

)あなたは

<View 
       android:layout_width="1dp" 
       android:layout_height="50dp" 
       android:background="#cdcdcd" /> 

2ビューを作成することができます)あなたは、リニアレイアウトを作成し、リニアレイアウトの左余白の色を設定することができますこれには以下の方法があります。

この方法は、私の作品

<LinearLayout 
      android:layout_width="5dp" 
      android:layout_height="100dp" 
      android:id="@+id/tactic_linear_layout" 
      android:background="@drawable/margin_color" 
      android:orientation="horizontal" 
      android:layout_marginLeft="20dp" 
      android:layout_marginTop="0dp" 
      android:paddingBottom="0dp"> 

はこれを試して

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 


<item> 
    <shape android:shape="rectangle" > 
     <solid android:color="#FFF" /> 
    </shape> 
</item> 

<item android:bottom="-4dp" android:right="-4dp" android:left="1dp" 
    android:top="-4dp"> 
    <shape> 
     <solid android:color="@android:color/transparent" /> 
     <stroke 
      android:dashGap="0px" 
      android:dashWidth="0px" 
      android:width="2dp" 
      android:color="#EF5350" /> 
    </shape> 
</item> 

が続いた背景として、リニアレイアウトにこのマージンを適用する描画可能なフォルダmargin_color.xmlの下で、このXMLファイルを作成します。 ....

関連する問題