java - How to set relativelayout height equal to its width? -


i searched lot find out how gonna work , got nothing. found java code dynamically didn't work ant of theme , when opening program, show force close. code:

<linearlayout android:baselinealigned="false"     android:layout_width="match_parent"     android:layout_height="wrap_content" >      <relativelayout         android:id="@+id/rlv1"         android:layout_width="match_parent"         android:layout_height="150dp"         android:layout_weight="1"         android:background="@drawable/rectengle2" >     </relativelayout>      <relativelayout         android:id="@+id/rlv2"         android:layout_width="fill_parent"         android:layout_weight="1"         android:background="@drawable/rectengle" >     </relativelayout>    </linearlayout> 

as can see created rectangle shape , used in relative layout lineaer layout parent , splitted linear layout verticali 2 part each relative layout. want set these relative layout height equal width pure square rectangle. tried many way ... can me guy please?? thnaks..

the simplest solution, imo, subclass relativelayout, , override onmeasure, providing super same size width , height. instance

@override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {   super.onmeasure(widthmeasurespec, widthmeasurespec); } 

as pointed out @zaktaccardi, declare in layout

<com.example.subclassrelativelayout  android:layout_width="match_parent" android:layout_height="wrap_content" /> 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -