嘿,我正在開發一個應用程式,其中有兩個按鈕“立即呼叫”和“立即聊天”。通常我們只顯示一個按鈕“立即聊天”。如果用戶提供選中“顯示呼叫按鈕”選項,那么我們將顯示兩個按鈕。否則只會顯示“立即聊天”按鈕。但是問題出在設計上,如果用戶啟用呼叫按鈕,那么它將看起來像這樣
像這樣。
它應該是什么樣子
但問題是,當我顯示兩者時,它看起來不錯,但當我只顯示“立即聊天”按鈕時,它看起來很奇怪,但它應該是。像這樣
它看起來如何
XML代碼
<LinearLayout
android:id="@ id/callNowLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginTop="300dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@ id/callNow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#FF5722"
android:padding="10dp"
android:text="Call Now"
android:textAllCaps="false"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@ id/chatNow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:padding="10dp"
android:text="Chat Now"
android:backgroundTint="#FF5722"
android:textAllCaps="false"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@ id/callNow" />
</LinearLayout>
uj5u.com熱心網友回復:
試試這個 XML 并根據您的代碼使用 if else 條件。根據條件以編程方式使用可見性。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@ id/callNowLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="@ id/callNow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:backgroundTint="#FF5722"
android:text="Call Now"
android:textAllCaps="false"
android:textColor="@color/white" />
<Button
android:id="@ id/chatNow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:backgroundTint="#FF5722"
android:text="Chat Now"
android:textAllCaps="false"
android:textColor="@color/white" />
</LinearLayout>
uj5u.com熱心網友回復:
嘗試這個
<LinearLayout
android:id="@ id/callNowLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginTop="300dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@ id/callNow"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="#FF5722"
android:padding="10dp"
android:text="Call Now"
android:textAllCaps="false"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@ id/chatNow"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:padding="10dp"
android:text="Chat Now"
android:backgroundTint="#FF5722"
android:textAllCaps="false"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@ id/callNow" />
</LinearLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/535897.html
