2016-01-28 16 views
5

Jak ustawić programowo margines procentowy dla widoku obrazu.Ustaw margines proporcjonalnego marginesu obliczeniowego programowo

<android.support.percent.PercentRelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/rating_thumb" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/thumb" /> 

</android.support.percent.PercentRelativeLayout> 

Odpowiedz

7

Po kilku godzinach szukania i poprawiania, w końcu otrzymałem odpowiedź.

imageView = (ImageView) view.findViewById(R.id.rating_thumb); 
PercentRelativeLayout.LayoutParams layoutParams = (PercentRelativeLayout.LayoutParams) imageView.getLayoutParams(); 
PercentLayoutHelper.PercentLayoutInfo percentLayoutInfo = layoutParams.getPercentLayoutInfo(); 
percentLayoutInfo.leftMarginPercent = 15 * 0.01f; //15 is the percentage value you want to set it to 
imageView.setLayoutParams(layoutParams); 
+1

setLayoutParams o nazwie requestLayout() – user949884

+0

Zaktualizowałem. – ayz4sci

Powiązane problemy