I have added a view into WebView , but the problem is after adding a view using webView.addView(myview) the layout of the myview resides on the top of the screen though i have set android:layout_gravity="bottom" in myviews's layout resource file.
so far i have tired following things
myview_layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/mc_track_icon"
>
</ImageView>
</LinearLayout>
i tried the relative layout too
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/mc_track_icon"
>
</ImageView>
</RelativeLayout>
Even i have tried to set the layout explicitly in code also
webView.add(myView,new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,Gravity.BOTTOM));
But the ImageView is visible on the top left corner only.
Maybe using a Relative layout would be better.Then in the yourlayout.xml add
android:layout_alignParentBottom="true" >
Related
I am trying to make a layout where there are a LinearLayout and inside it I want a FrameLayout and a button.
I want the button to use the bottom of the linearlayout and to use the maximum width and the enough height for the button, using wrap content.
The other component, the FrameLayout I want to use it the remaining part of the screen.
How can I do it?
Here it the layout so far..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="snapIt"
android:text="#string/Capture" />
</LinearLayout>
Is not showing the button :s
Thanks alot in advance ;)
Better to work out with relative layout with button aligned to parent bottom and your frame layout above it occupying the rest space of the screen.Like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_capture"/>
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
use the following xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"
android:text="capture" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_capture"
/>
</RelativeLayout>
i am just trying to make these layout, after compare my layout code and your layout code, i find a different code, there is in my code. Did you missing it or just move it away cause it useless from the layout code ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<FrameLayout
android:id="#id/flayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world">
</FrameLayout>
</LinearLayout>
I have an android application which has a Gallery. When the application run the images views in the middle of the screen, put I want to start the view from the left of screen.
I tried all the layout params like padding, margin, gravity and setSpacing, all of them not working to set the position of image to the left top of the linear layout.
<?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:layout_marginBottom="0dp"
android:orientation="vertical" >
<uk.co.senab.photoview.sample.HackyViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="404dp"
android:layout_weight="3" />
<RelativeLayout
android:id="#+id/actionBar"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<Gallery
android:id="#+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="left|top"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
1) You need RelativeLayout as parent.
2) Set attributes to your images view
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
p.s. show xml code of your layout
I've got two layouts first and second, I want to insert second to first.
I want to insert second layout into layout that has id #+id/layout
when I press button Get Layout, it show the the second layout on the bottom of button
first layout
<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:orientation="vertical" >
<Button
android:id="#+id/btn_get_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Layout" />
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
second layout
<?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:background="#drawable/card_base"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/img_cover"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:scaleType="fitXY"
android:src="#drawable/card_beauty" />
<ImageView
android:id="#+id/img_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="20dp"
android:scaleType="fitXY"
android:src="#drawable/sample_0" />
</RelativeLayout>
</LinearLayout>
if I understood you right you should use the following code within your first layout
<include
layout="#layout/second_layout"
android:id="#+id/includedLayout"
android:visibility="gone"
android:layout_below="#id/buttonId" />
and then in your button's action you just use
((RelativeLayout)findViewById(R.id.includedLayout)).setVisibility(View.VISIBLE);
LinearLayout placeHolder = (LinearLayout) findViewByid(R.id.layout);
getLayoutInflater().inflate(R.layout.second_layout, placeHolder);
Use include
Here is a somewhat fuller example. The square blue layout is inserted into the main layout using include.
activity_main.xml
This is the main layout. The custom layout is referenced using include. You can override any of the attributes here, too.
<?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:padding="16dp">
<!-- Here is the inserted layout -->
<include layout="#layout/my_layout"/>
</RelativeLayout>
my_layout.xml
This is the custom layout that will be inserted into the main layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="5dp"
android:text="My Layout"/>
</RelativeLayout>
You Should use this code snippet to add a Layout inside another one.
parentLayout=(LinearLayout)findViewById(R.id.parentLayout);
inflateView=View.inflate(this,R.layout.view_video,parentLayout);
Here the parentLayoutis the root View and R.layout.view_video is the layout that you need to insert.
Use LayoutInflator to inflate an external layout into existing layout. Checkout LayoutInflater on Android Dev Site for more information about it.
I have made layout for custom dialog, it has inside two imageview. I want to show both Imageview when dialog appear. and i want to hide the main layout of my xml file I have used "#00000000" as background:color, but it is not working.
Is there any way to do the same?
Thanks.
Here is my layout. I have taken screen shot please have a look i want to hide the border which are showing in image.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:background="#00000000">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<ImageView android:id="#+id/img_closeimage" android:src="#drawable/product_zoom_close"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:clickable="true"></ImageView>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout2"
android:layout_marginLeft="25dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="-5dip" android:layout_marginBottom="20dip" android:layout_marginRight="20dip">
<ImageView android:id="#+id/img_ProductZoom" android:src="#drawable/index"
android:layout_width="wrap_content" android:layout_height="wrap_content"
></ImageView>
</LinearLayout>
</LinearLayout>
image description here
Adinias comment is correct, your layout has quite some redundancy. You also say that you only want to show an imageview, but your layout contains two imageviews. If you only want to show one imageview, then your layout should look like this:
<?xml version="1.0" encoding="utf-8"?>
<ImageView android:id="#+id/img_ProductZoom" android:src="#drawable/index"
android:layout_width="wrap_content" android:layout_height="wrap_content"
/>
If you want to show two ImageViews, use this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:background="#00000000">
<ImageView android:id="#+id/img_closeimage" android:src="#drawable/product_zoom_close"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:clickable="true"/>
<ImageView android:id="#+id/img_ProductZoom" android:src="#drawable/index"
android:layout_width="wrap_content" android:layout_height="wrap_content"
/>
</LinearLayout>
Your current layout looks the way it does because you have specified the layout to take as much space as possible with android:layout_height="fill_parent" and android:layout_width="fill_parent". Try to use wrap_content as height and width instead.
it's just a simple question:
I have a layout file which is presented as an item inside of a ListView. I set the height of the RelativeLayout to 100dp, but it does not work, it's always wrapping the content, no matter which layout I use. What can I do to set a fixed value to the layout height without having it wrapping?
Thanks for the help.
<?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="100dp"> <!-- this attribute seems to be ignored -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="#dimen/progressbar_small"
android:layout_height="#dimen/progressbar_small"
android:layout_gravity="center_vertical" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/loading"
android:layout_gravity="center_vertical"
style="#style/ListItemSubtext" />
</LinearLayout>
</RelativeLayout>
Do like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="100dip">
I think in a list view all items are of the same height. In your case you could add the progress bar in the list footer view. Add a dummy height adjuster right before or after ListItemSubtext. Try using TableLayout instead of Relative and Linear Layout.
A dummy adjuster is like this.
<View android:layout_width="wrap_content" android:layout_height="100dip"/>
Please note you do not need xmlns in every element.
Try just using 100px. Works for me.
i do below changes in your xml..
<?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="100dp"> <!-- this attribute taking a fixed value as u said -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="20dip"
android:layout_height="20dip"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="#string/loading"
android:layout_gravity="center_vertical"
style="#style/ListItemSubtext" />
</LinearLayout>
If this doesn't work for you, say what exactly you want to do.