I created a layout, which has a imageview on the top, in the middle text and at the end a buttton. Now I want that all of these elements are on one page, that means the textview should scale his size automatically. Actually in my layout I only can see the imageview and the textview, for seeing the button I have to scroll.
Should I change the size of the textview by myself and adding different layouts for different screen sizes or is there another possibility?
My xml-code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RelativeLayout
android:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/crunch1" />
<ImageView
android:id="#+id/button2links"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView2"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#drawable/links2" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/b2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/l1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/crunch2" />
<ImageView
android:id="#+id/button2rechts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="#drawable/rechts2" />
</RelativeLayout>
</RelativeLayout>
</HorizontalScrollView>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Crunch"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/crunch" />
<ImageButton
android:id="#+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="verlaufKlick"
android:src="#drawable/ic_launcher"
android:visibility="invisible"
android:background="?android:selectableItemBackground"
/>
</LinearLayout>
</ScrollView>
Now I use this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical" >
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<RelativeLayout
android:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/crunch1" />
<ImageView
android:id="#+id/button2links"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView2"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#drawable/links2" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/crunch2" />
<ImageView
android:id="#+id/button2rechts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:src="#drawable/rechts2" />
</RelativeLayout>
</HorizontalScrollView>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Crunch"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_below="#+id/horizontalScrollView1" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="#string/crunch"
android:layout_below="#+id/textView2"
android:layout_above="#+id/pause"
android:adjustViewBounds="true"
android:scaleType="centerCrop"/>
<ImageButton
android:id="#+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="verlaufKlick"
android:src="#drawable/ic_launcher"
android:visibility="invisible"
android:background="?android:selectableItemBackground"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Related
I am using listiview for my application,in my listiview i set something like this
listitem1(Image)
listitem2(Image+Image)
Now issue is in my second row i want to get space between two images,but it is not working,following is my xml layout and screen shot of my output
listview_view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F3F3F3"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/lnrsearchviews"
android:layout_below="#+id/imgshead"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/rect_search"
>
<!--<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/searchs"
android:layout_gravity="center_vertical"
/>-->
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/autosearchbyname"
android:hint="Search"
/>
</LinearLayout>
<!-- <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_shopbydept"
android:text="Shop By Departments"
android:textSize="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_below="#+id/lnrsearchviews"
/>-->
<ListView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/list_menu"
android:layout_below="#+id/lnrsearchviews"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginBottom="20dp"
android:dividerHeight="8dp"
android:divider="#f3f3f3"
></ListView>
</RelativeLayout>
list_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:id="#+id/btntest"
android:background="#drawable/ab"
android:orientation="horizontal"
>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="180dp"
android:id="#+id/id"
android:background="#drawable/heads"
android:layout_weight="1.17">
<RelativeLayout
android:layout_height="40dp"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:padding="2dp"
android:text="abd"
android:id="#+id/txt_allproductsname"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:padding="2dp"
android:text="abddd"
android:id="#+id/txt_allproductsquty"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Mygetview
http://pastie.org/10289187#5
Try this as your list_item and use set visibility of the second ImageView to gone when you need to show only one image.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/first_imageview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#9ff0"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/second_imageview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#9ff0"
android:src="#drawable/ic_launcher" />
</LinearLayout>
I'm designing my application. In which I want to set TextView on top of an ImageView without any correction of any Layout. TextView is on top of ImageView like other two Buttons. Is it possible to set TextView on ImageView. In my code TextView is hidden behind ImageView. Here is my code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="0dp"
android:background="#drawable/call_bg" >
<RelativeLayout
android:id="#+id/rl_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rl_photo"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="20dp" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/relativeLayout1"
android:layout_marginTop="350dp"
android:orientation="horizontal"
android:weightSum="2" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/receive1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#drawable/acceptxml" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/reject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/rejectxml" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
My Actual Code is like this. this is perfectly working in application. but when i change this like your code. so its contain error.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:background="#drawable/call_bg" >
<RelativeLayout
android:id="#+id/rl_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#id/rl_photo" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/relativeLayout1"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="2" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/receive1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#drawable/acceptxml" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/reject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/rejectxml" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
Check this and let me know.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="0dp"
android:background="#cccccc" >
<RelativeLayout
android:id="#+id/rl_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Medium Text"
android:textColor="#ff0000"
android:textStyle="bold"
android:layout_centerInParent="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rl_photo"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="20dp" >
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/relativeLayout1"
android:layout_marginTop="350dp"
android:orientation="horizontal"
android:weightSum="2" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/receive1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/reject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".85" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>
<LinearLayout
android:id="#+id/container2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".15"
android:orientation="horizontal"
android:weightSum="2" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/receive1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/reject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
// Try this way,hope this will help you to solve your problem...
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:orientation="vertical"
android:padding="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_marginTop="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="bottom"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hugh Jackman"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(201) 555-5555"
android:layout_marginTop="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:padding="5dp">
<Button
android:id="#+id/receive1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#drawable/acceptxml" />
<Button
android:id="#+id/reject"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#drawable/rejectxml" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
I want to show four images as shown in given imaages . each image must be equally far apart from others I have tried a LinearLayout and use it weight property but all in sane.
I have eight icons, four for selected state and four for unselected state. I have tried many ways,
Thanks in Advance.
Image Icons are ..
xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom" />
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/article_icn"
android:padding="10dp"
android:layout_margin="10dp"
android:scaleType="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/forum_icn"
android:padding="10dp"
android:layout_margin="10dp"
android:scaleType="fitXY" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/profile_icn"
android:padding="10dp"
android:layout_margin="10dp"
android:scaleType="fitXY" />
</LinearLayout>
</RelativeLayout>
I tried your code and modified a bit:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom" />
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="3" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/icon"
android:padding="10dp"
android:scaleType="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/icon"
android:padding="10dp"
android:scaleType="fitXY" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/icon"
android:padding="10dp"
android:scaleType="fitXY" />
</LinearLayout>
</RelativeLayout>
Assigning android:weightSum="3" to container and weight 1 to all images works fine:
Output:
Check this layout, works exactly as you want. Just replace the image icons and background.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#517398" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_agenda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
OUTPUT
You can use weight attrib:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
</LinearLayout>
output is like this:
Try this..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom" />
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Screen
I am trying to make images in this layout (with id itemslayout) wrap the image rather than match the parent height. The imageviews dont seem to listen to my XML code! What is the solution. Here is the XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/pullupTitleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/orange"
android:orientation="vertical" >
<xx.xxxxxx.xxxxx.android.ui.views.CustomTextView
android:id="#+id/someTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:text="#string/lolperks"
android:textColor="#color/white"
android:textSize="22sp" />
<Button
android:id="#+id/upanddownButton"
style="#style/OrangeSmallButton"
android:layout_width="37dp"
android:layout_height="34dp"
android:layout_gravity="right"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp"
android:background="#drawable/double_arrows"
android:contentDescription="UpButton"
android:onClick="downButtonClicked"
android:scaleY="-1"
android:text=" " />
</FrameLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="pick a card any card "
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:id="#+id/itemslayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.333" >
<ImageView
android:id="#+id/ImageView02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/card" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.333" >
<ImageView
android:id="#+id/ImageView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/card" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.333"
android:layout_margin="10dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/card" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
here is a screenshot of what is happening. I need it to be wrapping the image not matching the parent.
What i want:
I know it might sound confusing, but try putting one more layout inside of the outermost layout and set the height to wrap_content. With layouts, it causes everything inside of it to wrap content rather than causing the actual layout to do it. You need this buffer layout though so that the outermost layout will still fill the whole screen.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/pullupTitleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/orange"
android:orientation="vertical" >
<xx.xxxxxx.xxxxx.android.ui.views.CustomTextView
android:id="#+id/someTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:text="#string/lolperks"
android:textColor="#color/white"
android:textSize="22sp" />
<Button
android:id="#+id/upanddownButton"
style="#style/OrangeSmallButton"
android:layout_width="37dp"
android:layout_height="34dp"
android:layout_gravity="right"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp"
android:background="#drawable/double_arrows"
android:contentDescription="UpButton"
android:onClick="downButtonClicked"
android:scaleY="-1"
android:text=" " />
</FrameLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="pick a card any card "
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:id="#+id/itemslayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.333" >
<ImageView
android:id="#+id/ImageView02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/card" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.333" >
<ImageView
android:id="#+id/ImageView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/card" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.333"
android:layout_margin="10dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/card" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
how do i align three imageview horizontally like this image http://imgur.com/isvfTqZ how to make this typelayout. it is linearlayout or Relativelayout help me???
How can I make vertical combination of imageview and textview horizontally...?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="92dp"
android:background="#F9F939"
android:src="#drawable/ic_launcher"
android:layout_toLeftOf ="#+id/imageView6"
android:layout_centerInParent="true"
android:padding="15dp" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#54F71D"
android:src="#drawable/ic_launcher"
android:layout_centerInParent="true"
android:padding="15dp"
android:layout_margin="10dp" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1DF7AB"
android:src="#drawable/ic_launcher"
android:layout_centerInParent="true"
android:layout_toRightOf="#+id/imageView6"
android:padding="15dp" />
</RelativeLayout>
Use LinearLayout with orientation = horizontal
You can do like this...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#null"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="#null"
android:text="#string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#null"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="#null"
android:text="#string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgHome2Imag3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#null"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="#null"
android:text="#string/hello_world" />
</LinearLayout>
</LinearLayout>
use the property of android:layout_toLeftOf="+#id/img1" or android:layout_toRightOf="+#id/img1" if you want to use Relative layout. Otherwise its alright to go with the LinearLayout.