I have declared Linear Layout in my main_layout.xml, which has layout_with with value of match_parent and I am trying to get the width of Linear Layout programmatically in pixles, but i am getting width 0. Here is my main_layout.xml.
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.bairnlogixgame.MainActivity" >
<LinearLayout
android:id="@+id/llTextvieConainter"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="@drawable/view_borders"
android:orientation="vertical"
/>
</RelativeLayout>
Here is my MainActivity code.
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMainContainer = (LinearLayout) findViewById(R.id.llTextvieConainter);
int mWidth = getBoxDimensions(mMainContainer)[0];
Log.i(TypeRacingConstants.LOGCAT,
"Width of box :" + mWidth);
}
private int[] getBoxDimensions(LinearLayout linearLayout) {
int boxDiamensions[] = { 0, 0 };
linearLayout.measure(MeasureSpec.EXACTLY, MeasureSpec.EXACTLY);
boxDiamensions[0] = linearLayout.getMeasuredWidth();
boxDiamensions[1] = linearLayout.getMeasuredHeight();
return boxDiamensions;
}
}
Please help me, where i am getting wrong.
No comments:
Post a Comment