I want to set my webview under my gridview via xml - android

I want to set my webview under my gridview via xml. I want to look something like that
But right now its look like this, webview is diagonal to gridview
This is my code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Contacts"
android:background="#drawable/gradient"
android:orientation="horizontal">
<GridView
android:layout_width="match_parent"
android:layout_height="450dp"
android:numColumns="2"
android:horizontalSpacing="4dp"
android:verticalSpacing="4dp"
android:id="#+id/gridView"
/>
<WebView
android:layout_width="match_parent"
android:layout_height="550dp"
android:layout_marginTop="180dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/gridView"
/>
</LinearLayout>
But i want to set the images from string array. For wxample

Related

Gridview inside scrollview not working properly

I am trying to design a layout as shown in below image. It contains an ImageView for cover image, GridView in which each cell will act as a button for performing various actions and below that TextView as footer.
I am not able to achieve this thing. Below is my xml code:
home.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<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="7">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_weight="3"
android:scaleType="centerCrop"
android:src="#drawable/xyz" />
<GridView
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:background="#000000"
android:columnWidth="100dp"
android:horizontalSpacing="1dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp"></GridView>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="OSKAR" />
</LinearLayout>
singlegrid.xml
<?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="200dp"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:id="#+id/grid_img"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="#+id/grid_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" />
</LinearLayout>
I am struggling with this issue and searched a lot with various solutions but not able to find out the correct one. Thanks in advance.
I think Why should you use scrollView?
Without scrollview your requirement satisfied.
you can set height of grid's child dyanamically like below:
Child_item_height=
(screenheight - (toolbar_height+imageview_height+footer_height+textview_height))/2
Note: you can set textview height fix like 20dp.
Using above login you can get height of grid so that you can display 4 grid in screen and another grid in scroll.

MPAndroid adjustment to screen size without fixed height

So I have been trying every mix and match with different layouts and settings and still cant figure out how to make this work. I want to have a spinner on the Same Screen as an MPAndroid Line Chart, I know I can fix the height Manually and adjust it to fit properly, but fill parent or match parent does not account for the spinner and just pushes it off the screen! If I load the application on my phone with height of 290dp Great fits perfectly! Load it on the 7" tablet not so pretty... Half the screen is empty. How do I contain the Chart to fill a layout that accounts for spinner? Wrap Content on the chart makes it unusable.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".history"
android:background="#303030">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/chart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner4"
android:entries="#array/list3"
android:popupBackground="#303030"
android:layout_centerHorizontal="true" />
</LinearLayout>
Try using this I have removed some attributes which were missing at my end. This is where spinner is on top and rest is filled with line chart.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#303030"
android:orientation="vertical">
<Spinner
android:id="#+id/spinner4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:popupBackground="#303030" />
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/chart"
android:layout_width="fill_parent"
android:layout_below="#+id/spinner4"
android:layout_height="fill_parent" />
</RelativeLayout>
Try this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".history"
android:background="#303030">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="70">
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/chart"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<Spinner
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="30"
android:id="#+id/spinner4"
android:entries="#array/list3"
android:popupBackground="#303030"
android:layout_centerHorizontal="true" />
</LinearLayout>
Because of using weight, on any screen "map and spinner" will look like in same screen height ratio.

Can I overlap the WebView with an ImageButton?

What I want to create should look like this :
I want it like this because I want the button to cover a part of the content of the webview making it unreachable for the user.
You can do it using FrameLayout as follows...
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Button" />
</FrameLayout>
Yes You can do.for that purpose you have to use relative layout.first you have add webview,then add image button and set gravity bottom to image button.i think this can help you.
<?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:orientation="vertical" >
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dp"
/>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#android:color/darker_gray"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

How to show other views after list view height set to fill_parent

To prevent multiple GetView calling I have set the height of ListView to fill_parent.
How to show other views than the ListView itself?
The following layout is inflated in a ViewPager:
<?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"
android:padding="15dp" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
where the included layout is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dp" >
<ScrollView
android:id="#+id/prontuariohome_scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none" >
.
.
.
.
</ScrollView>
</LinearLayout>
EDIT: This solution won't work for view higher than a button
I don't understand what you want to achieve, but if you NEED to have the height as fill_parent for some reason and can't be any other value, you can put the ListView with inside a LinearLayout with the height="0dp" and weight="1". So would be something like this:
<?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"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>
Try to use following code
android:layout_height="0dp"
android:layout_weight="1"
in ListView tag
With android:layout_height="0dip" the view will take the rest of the free place
You said this solution is wont work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/lv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" android:layout_above="#+id/bt"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bt" android:layout_alignParentBottom="true"/>
just add it a android:layout_above="#+id/bt" to listview.
I'm sorry for being not clear.
Here is the link of the (probably) main thread asked here in Sof about the issue I was talking about.
After some tries I'm happy to give you the solution of my problem.
Giving another layout above the ListView lets the LV cuts the space not filled by the ListView itself
<?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"
android:padding="15dp" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="#+id/lv_viol_infraction"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<include layout="#layout/activity_prontuario_home" />
</LinearLayout>

Gridview adapter within an adapter

In reference to this question. I have hit a wall, I have both of my adapters set up, and my xml files are nicely lined up. In my activity I have set my content view to the main xml which contains the top gridview. In the adapter I have linked my Imageview to the gridview.
The problem is how do I go about setting the grid_item.xml as my contentview for the inner adapter so that I can link the next image view to the xml?
These are my xml files in order:
main_layout.xml
<?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" >
<GridView
android:id="#+id/gridview_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:columnWidth="60sp"
android:gravity="center"
android:horizontalSpacing="10sp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10sp"
android:clipChildren="true" />
</LinearLayout>
grid_item.xml
<?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" >
<ImageView
android:id="#+id/category_main_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow_left_dark" />
<GridView
android:id="#+id/gridview_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5sp"
android:columnWidth="90sp"
android:gravity="center"
android:horizontalSpacing="10sp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10sp"
android:clipChildren="true" />
</LinearLayout>
item_grid_image.xml
<?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" >
<ImageView
android:id="#+id/item_main_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow_left_dark" />
</LinearLayout>
I need to get the content of my grid_item.xml for my inner adapter. Any ideas?
Ended up settings views (views with images) dependant on the amount of children. Adding a gridview to each gridview element ended up messing up scrolling :).

Categories

Resources