ConstraintLayout實現(xiàn)物流詳情效果

ConstraintLayout實現(xiàn)跟隨其他控件動態(tài)線高度效果,效果圖:


1550803499(1).png

物流信息不固定所以這里使用的RecyclerView實現(xiàn)動態(tài)顯示酝润,Activity 布局代碼:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
            android:paddingTop="50dp"
            android:paddingBottom="50dp"
            android:background="#fff"
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

代碼使用的Kotlin(不得不說代碼簡潔了很多):


        rv.layoutManager=LinearLayoutManager(this)
        rv.adapter=MyAdapter(this)

Adapter:


import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.item_logistics_detail.view.*

class MyAdapter(private val mContext: Context) : RecyclerView.Adapter<MyAdapter.MyViewHolder>() {

    override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): MyViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.item_logistics_detail, viewGroup, false)
        return MyViewHolder(view)
    }

    override fun onBindViewHolder(myViewHolder: MyViewHolder, i: Int) {
        myViewHolder.itemView.item_logistics_detail_ysh_tv.text=(i+1).toString()
        when(i){
            1->{
                myViewHolder.itemView.item_logistics_detail_start_receive_address_text_view.text="中華人民共和國新疆維吾爾自治區(qū) \n伊犁哈薩克自治州塔城地區(qū)和布克賽爾蒙古自治縣和什托洛蓋鎮(zhèn)西特木恩哈布其克村"
            }
            3->{
                myViewHolder.itemView.item_logistics_line_v.visibility=View.GONE
                myViewHolder.itemView.item_logistics_detail_start_receive_address_text_view.text="已收貨"
            }
        }
    }

    override fun getItemCount(): Int {
        return 4
    }

    inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}

之后就是最主要的item的布局代碼:


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                             android:layout_width="match_parent"
                                             android:layout_height="wrap_content"
                                             xmlns:app="http://schemas.android.com/apk/res-auto"
                                             android:background="#fff">

    <TextView
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:id="@+id/item_logistics_detail_start_date_text_view"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="3dp"
            android:gravity="right"
            android:text="09-12"
            android:textColor="#A2A8B6"
            android:textSize="12sp"/>

    <TextView
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@id/item_logistics_detail_start_date_text_view"
            android:id="@+id/item_logistics_detail_start_time_text_view"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/item_logistics_detail_start_date_text_view"
            android:gravity="right"
            android:text="07:20"
            android:textColor="#A2A8B6"
            android:textSize="10sp"/>

    <TextView
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            android:id="@+id/item_logistics_detail_start_receive_address_text_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="98dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="3dp"
            android:paddingBottom="15dp"
            android:text="已到達xx市xx區(qū)xx路xxx號xx大廈xx樓..............................haha"
            android:textColor="#A2A8B6"
            android:textSize="14sp"/>
    <TextView
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            android:textColor="#fff"
            android:gravity="center"
            android:text="1"
            android:textSize="14sp"
            android:src="@mipmap/ic_launcher_round"
            android:id="@+id/item_logistics_detail_ysh_tv"
            android:background="@drawable/shape_oval_999999"
            android:layout_marginLeft="61dp"
            android:layout_width="24dp"
            android:layout_height="24dp"/>
    <View
            android:id="@+id/item_logistics_hint_line_v"
            android:background="#fff"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_width="match_parent"
            android:layout_height="1px"/>
    <View
            android:id="@+id/item_logistics_line_v"
            app:layout_constraintTop_toBottomOf="@id/item_logistics_detail_ysh_tv"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintBottom_toTopOf="@id/item_logistics_hint_line_v"
            android:layout_width="1dp"
            android:layout_height="0dp"
            android:layout_marginLeft="73dp"
            android:background="@color/colorPrimary"/>


</android.support.constraint.ConstraintLayout>

注:

 app:layout_constraintLeft_toLeftOf="parent" 

app:layout_constraintTop_toBottomOf="@id/item_logistics_detail_ysh_tv"

這些屬性可以直接通過字面解讀 蓉坎,constraintLeft指當(dāng)前的view的那個方向陕悬,toLeftOf相對于"parent" 或者其他view位置所在的方向灌诅,第一個可以解讀為這個view的左側(cè)相對于父容器的左側(cè)践磅。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末单刁,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子音诈,更是在濱河造成了極大的恐慌幻碱,老刑警劉巖绎狭,帶你破解...
    沈念sama閱讀 218,451評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件细溅,死亡現(xiàn)場離奇詭異,居然都是意外死亡儡嘶,警方通過查閱死者的電腦和手機喇聊,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,172評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蹦狂,“玉大人誓篱,你說我怎么就攤上這事】ǎ” “怎么了窜骄?”我有些...
    開封第一講書人閱讀 164,782評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長摆屯。 經(jīng)常有香客問我邻遏,道長,這世上最難降的妖魔是什么虐骑? 我笑而不...
    開封第一講書人閱讀 58,709評論 1 294
  • 正文 為了忘掉前任准验,我火速辦了婚禮,結(jié)果婚禮上廷没,老公的妹妹穿的比我還像新娘糊饱。我一直安慰自己,他們只是感情好颠黎,可當(dāng)我...
    茶點故事閱讀 67,733評論 6 392
  • 文/花漫 我一把揭開白布另锋。 她就那樣靜靜地躺著滞项,像睡著了一般。 火紅的嫁衣襯著肌膚如雪砰蠢。 梳的紋絲不亂的頭發(fā)上蓖扑,一...
    開封第一講書人閱讀 51,578評論 1 305
  • 那天,我揣著相機與錄音台舱,去河邊找鬼律杠。 笑死,一個胖子當(dāng)著我的面吹牛竞惋,可吹牛的內(nèi)容都是我干的柜去。 我是一名探鬼主播,決...
    沈念sama閱讀 40,320評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼拆宛,長吁一口氣:“原來是場噩夢啊……” “哼嗓奢!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起浑厚,我...
    開封第一講書人閱讀 39,241評論 0 276
  • 序言:老撾萬榮一對情侶失蹤股耽,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后钳幅,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體物蝙,經(jīng)...
    沈念sama閱讀 45,686評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,878評論 3 336
  • 正文 我和宋清朗相戀三年敢艰,在試婚紗的時候發(fā)現(xiàn)自己被綠了诬乞。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,992評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡钠导,死狀恐怖震嫉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情牡属,我是刑警寧澤票堵,帶...
    沈念sama閱讀 35,715評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站逮栅,受9級特大地震影響悴势,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜证芭,卻給世界環(huán)境...
    茶點故事閱讀 41,336評論 3 330
  • 文/蒙蒙 一瞳浦、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧废士,春花似錦叫潦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,912評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽短蜕。三九已至,卻和暖如春傻咖,著一層夾襖步出監(jiān)牢的瞬間朋魔,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,040評論 1 270
  • 我被黑心中介騙來泰國打工卿操, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留警检,地道東北人。 一個月前我還...
    沈念sama閱讀 48,173評論 3 370
  • 正文 我出身青樓害淤,卻偏偏與公主長得像扇雕,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子窥摄,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,947評論 2 355