我有一個以屏幕爲中心的LinearLayout。它的寬度小於屏幕寬度。有兩個按鈕:右箭頭和左箭頭。 當用戶按下相關按鈕時,佈局應從相關側增加其寬度。另一方應該保持在那裏。從右側或左側增加LinearLayout寬度
現在設置寬度從兩側同樣增加布局。佈局需要首先居中,並且必須通過用戶的輸入從任一側擴展。 (用例是爲了找到左右邊界不相等的圖像的相關部分的寬度,所以用戶必須使用我的技術來標記它們)。
我正在使用以下來增加寬度,但它具有上述行爲。 PS:該功能自Tasker應用早期開始實施;所以這是可能的。編輯: 這是佈局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:gravity="top"
android:layout_gravity="top"
android:id="@+id/iv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
<LinearLayout
android:id="@+id/llRightLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<Button
android:id="@+id/bLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LEFT" />
<Button
android:id="@+id/bRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RIGHT" />
</LinearLayout>
<LinearLayout
android:layout_gravity="center_horizontal"
android:id="@+id/llCropOverlay"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@color/colorCropOverlay"
android:orientation="vertical" />
</FrameLayout>
</LinearLayout>
最後的LinearLayout(llCropOverlay)應調整。請注意,我在編程上將寬度更改爲300,然後再使用調整按鈕的大小,以便測試按鈕是否正常工作。
後的完整佈局。有辦法做到這一點,但它不只是你的佈局參數的問題,而是你如何佈置在你的父母。 –
發佈了xml代碼 – Usman
如何改變佈局的寬度而不是改變頁邊距? 'match_parent' + L-margin> R-margin,如果你想正確地移動/展開它。 (等於模擬居中) – TWL