2016-11-30 12 views
1

アンドロイドスタジオで以下のようなxmlレイアウトを作成する簡単な方法はありますか?私は、iOS XCodeの男であり、比率の制約を使ってこれを行うには問題はありません。同じ幅と高さのビュー

これまでのところ、パーセントオプションを使用してConstraintLayoutと垂直gridlinesを使用しています。しかし、これは、私に等しい幅view1とview2を与え、高さを与えません。

私はonMeasureメソッドをオーバーライドすることを知っていますが、避けたいのです。

   a 
--------------------------- 
|       | 
|       | 
|       | 
|       | 
|  b   b  | 
| ----------- ----------- | 
| | view1 | | view2 | | 
| |b  | |b  | | 
| |   | |   | | 
| ----------- ----------- | 
--------------------------- 

b = 50% * a; 

答えて

0

あなたはこのような何かを行うことができます。

ImageView view_instance1 = (ImageView)findViewById(R.id.imageView1); 
ImageView view_instance2 = (ImageView)findViewById(R.id.imageView2); 
     LinearLayout.LayoutParams params=(LinearLayout.LayoutParams)view_instance1 .getLayoutParams(); 
     params.height= params.width; 
     view_instance1 .setLayoutParams(params); 
     view_instance2 .setLayoutParams(params); 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/imageview1" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 

    <ImageView 
     android:id="@+id/imageview2" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

</RelativeLayout> 

今、あなたの活動又はその断片に、あなたがしてfindViewById();

とで2つのビューを取得します

関連する問題