Trouble with ImageView gravity on Java, Android
I have this code:
<LinearLayout
android:layout_weight="0.5"
android:layout_width="0px"
android:id="@+id/linearLayout2"
android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout
android:layout_weight="0.45"
android:layout_width="fill_parent"
android:id="@+id/linearLayoutMainLogo"
android:orientation="horizontal"
android:gravity="center"
android:layout_height="0px">
<ImageView
android:src="@drawable/logo"
android:layout_gravity="center"
开发者_运维技巧 android:layout_width="wrap_content"
android:id="@+id/imageViewLogo"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
I need to set ImageView in center of LinearLayout by horizontal and by vertical simultaneously, but my code doesn't work. Where did I do mistake? Thank you
This is wrong i think: android:layout_width="0px" android:layout_height="0px"
Just correct with this:
<LinearLayout
android:layout_width="fill_parent"
android:id="@+id/linearLayout2"
android:orientation="vertical"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_weight="0.45"
android:layout_width="fill_parent"
android:id="@+id/linearLayoutMainLogo"
android:orientation="horizontal"
android:gravity="center"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/icon"
android:gravity="center"
android:layout_width="wrap_content"
android:id="@+id/imageViewLogo"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
精彩评论