第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Android/Java:布局自動換行

Android/Java:布局自動換行

HUWWW 2022-05-25 16:52:52
我的 android 應(yīng)用程序中有一個必須顯示鍵值對列表的活動。key 和 value 都是長度不統(tǒng)一的字符串資源。鍵應(yīng)左對齊,值應(yīng)右對齊。如果 key 和 value 在屏幕上排成一行,則它們應(yīng)相鄰顯示,而換行符應(yīng)將 key 和 value 分開。我為列表項創(chuàng)建了兩種布局,一種帶有換行符,一種沒有,如下圖所示:如何在我的活動的 ListView 中自動顯示正確的列表項?編輯:根據(jù)要求,我還添加了我的源代碼(我認(rèn)為這不是很有幫助,兩個布局文件之間的區(qū)別必須在我將列表布局片段添加到我的 ListView 的部分中完成。但是,在這個地方我將不得不解決許多其他問題,例如確定字符串資源的長度、確定可用于顯示布局的空間以及創(chuàng)建對可用空間變化做出反應(yīng)的處理程序。因此我更喜歡@bwt 提出的解決方案)<?xml version="1.0" encoding="utf-8"?><RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_marginTop="@dimen/margin_6">    <TextView        android:id="@+id/listitem_key"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentStart="true"        tools:text="Key"/>    <TextView        android:id="@+id/listitem_value"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentEnd="true"        tools:text="Value"/></RelativeLayout>并帶有換行符<?xml version="1.0" encoding="utf-8"?><RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_marginTop="@dimen/margin_6">    <TextView        android:id="@+id/listitem_key"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentStart="true"        tools:text="Key with a very long text constant"/>    <TextView        android:id="@+id/listitem_value"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/listitem_key"        android:layout_alignParentEnd="true"        tools:text="Value with a very long text constant"/></RelativeLayout>
查看完整描述

2 回答

?
搖曳的薔薇

TA貢獻(xiàn)1793條經(jīng)驗 獲得超6個贊

自動包裝視圖是 Google 的FlexboxLayout的一個典型用例。在您的情況下,它可能類似于:


<com.google.android.flexbox.FlexboxLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    app:alignContent="flex_start"

    app:flexWrap="wrap">


    <TextView

        android:id="@+id/textview1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" />


    <!-- right justified (using the remaining space) -->

    <TextView

        android:id="@+id/textview2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:gravity="end"

        app:layout_flexGrow="1" />


</com.google.android.flexbox.FlexboxLayout>


查看完整回答
反對 回復(fù) 2022-05-25
?
慕尼黑5688855

TA貢獻(xiàn)1848條經(jīng)驗 獲得超2個贊

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:paddingBottom="10dp"

android:paddingTop="10dp">


<TextView

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:gravity="right"

    android:layout_alignParentRight="true"

    android:layout_alignParentEnd="true"

    android:orientation="vertical"

    android:id="@+id/text1"/>

<TextView

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:gravity="left"

    android:id="@+id/notification_message"

    android:layout_alignParentLeft="true"

    android:layout_alignParentStart="true"

    android:layout_alignParentTop="true"

    android:layout_toLeftOf="@id/text1"

    android:layout_toStartOf="@id/text1"/>



</RelativeLayout>


查看完整回答
反對 回復(fù) 2022-05-25
  • 2 回答
  • 0 關(guān)注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號