1

這看起來很簡單,添加垂直指引後,當您點擊上箭頭時,它會變成百分比,但是我的android studio中或者我使用的約束佈局版本中有錯誤或者可能是我在這裏做了非常錯誤的事情。如何將垂直指標轉換爲百分比

enter image description here

我已經嘗試了一切,但它總是顯示了同樣的arrorw,從來沒有打開自己的百分比,當我點擊它。

我正在使用Android Studio 2.2,並將其添加到我的gradle中。

compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'

請指導我如何將其轉換爲百分比。

+0

或者,嘗試使用android.support.percent.PercentRelativeLayout或PercentFrameLayout視圖(可以在支持庫中找到這些視圖 - com.android.support:percent)。然後你可以使用app:layout_widthPercent =「num%」或其子類似的約束。 – MVojtkovszky

回答

3

它可以在Android Studio中2.3

compile 'com.android.support.constraint:constraint-layout:1.0.1' 

但是,有幾個問題s的用法。有時,圖標隱藏在其他項目下,難以點擊,並且在其他時間單擊圖標將在下面選擇一些內容。我發現你有時需要放大很多,然後在小三角形圖標的中間點擊右鍵。一次點擊就會顛倒指南的方向,兩次點擊會將其轉換爲百分比。

如果失敗,您可以隨時直接更改xml。更換

app:layout_constraintGuide_begin="51dp" 

app:layout_constraintGuide_percent="0.3611111" 

例如。

1

你可以使用Percent Support Library

百分比包提供的API支持添加和您的應用程序管理基於 個維度。

添加依賴於你的搖籃構建腳本,修改版本取決於您的項目:

compile 'com.android.support:percent:24.2.1' 

在你的佈局,你可以添加一個PercentRelativeLayout

您可以通過使用屬性 與 「百分比」 後綴

例如指定尺寸或孩子的保證金:

<android.support.percent.PercentRelativeLayout 
     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"> 
    <ImageView 
     app:layout_widthPercent="50%" 
     app:layout_heightPercent="50%" 
     app:layout_marginTopPercent="25%" 
     app:layout_marginLeftPercent="25%"/> 
</android.support.percent.PercentRelativeLayout> 
+0

@ Kirmani88請接受它是否有用 – LaurentY