I'm developing an android application, The layout is shown in the image below :
Screenshot http://www.lebanon-trading-center.com/daymanager/layout.PNG
The layout contains 2 main linearlayouts : a horizontal layout that takes 90% of the height of the device and a vertical layout that takes 10% of it. Inside the horizontal linearlayout there is three linearlayout ( two red and one containing an imageview). Each red layout is 10% of the width of the screen and the one containing the ImageView is 80%. Here is the xml code :
<?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:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.9"
android:weightSum="1"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.1"
android:background="#ff0000" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_weight="0.8" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.1"
android:background="#ff0000" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.1"
android:background="#000000" >
</LinearLayout>
</LinearLayout>
The problem is, when I set a PNG image (1036px X 730px ) as a source to the ImageView, the ImageView will get over the bottom linearlayout ( the black one ) and the two red layouts will be squeezed.
Screenshot http://www.lebanon-trading-center.com/daymanager/layout2.PNG
My question is how can I solve the problem and have the same layouts functional on all kind of tablets ?
Try this way,hope this will help you to solve your problem.
<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="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="0.90">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.10"
android:background="#ff0000" >
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_weight="0.80" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.10"
android:background="#ff0000" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="0.10"
android:background="#000000" >
</LinearLayout>
</LinearLayout>
Related
When I place a RecyclerView as a child of a ScrollView, marginBottom and paddingBottom doesn't work. Setting these values for the parent LinearLayout doesn't affect anything either. It seems that the ScrollView doesn't scroll to the bottom because the ScrollBar doesn't reach the bottom. How can I fix this bug?
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<!--To avoid scroll view from scrolling to the bottom automatically-->
<View android:layout_width="match_parent" android:id="#+id/focus_view" android:layout_height="0dp" android:focusable="true" android:focusableInTouchMode="true"><requestFocus/></View>
<ScrollView
android:id="#+id/sv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="4dp">
<LinearLayout
android:id="#+id/ll_categories_statistics_filters_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp">
<LinearLayout
android:id="#+id/ll_categories_statistics_select_date_fragment_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/border_primary_light"
android:padding="4dp"
android:layout_marginEnd="4dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/border_accent"
android:padding="4dp">
<Spinner
android:id="#+id/spn_categories_statistics_bill_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/pc_categories_statistics"
android:layout_width="match_parent"
android:layout_height="325dp"
android:layout_margin="4dp"/>
<fragment
android:id="#+id/fgm_categories_statistics_not_enough_data"
class="com.dolinsek.elias.cashcockpit.NotEnoughDataFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:text="#string/label_not_enough_data_for_statistic"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="8dp"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
Have you tried clipToPadding
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp"
android:clipToPadding="false"/>
Hello i use a card view with 6dp in elevation
but in my code when
height_4_3 = Functions.GetHeight4_3(parent.getWidth())
holder.parent_image.getLayoutParams().height = height_4_3;
holder.parent_image.requestLayout();
and i have a text view with 4:1 aspect
holder.parent_text_view.getLayoutParams().height = height_4_3 / 3
holder.parent_text_view.requestLayout();
i need subtracting the number elevation in aspect 4:3 and 4:1 that the elements are being put one over the other
UPDATE
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
card_view:cardElevation="6dp"
android:layout_width="match_parent"
android:id="#+id/parent_card_view"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp"
card_view:cardUseCompatPadding="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/parent_image"
android:layout_height="100dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:srcCompat="#drawable/login_1"
android:id="#+id/image_course"
android:elevation="2dp"
android:scaleType="centerCrop"
android:src="#drawable/login_1" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:layout_height="100dp"
android:id="#+id/parent_text_view">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textView3"
android:textColor="#color/BLUE_HIGHT" />
</LinearLayout>
</FrameLayout>
I created the following DialogFragment in XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/mainLayout"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/quoteLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<Button
android:id="#id/getMoreButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/getMore"
android:onClick="getMore" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/adLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</LinearLayout>
I've been working along on the quoteLayout section and have it performing as I wish. Now I wanted to fill the other sections with a button and an ad.
The problem is that nothing still shows up in the other parts of the mainLayout. The end of the screen is the end of the quoteLayout.
Any ideas?
You have it orientation set as vertical but in your linearlayout children you have the android:layout_height attribute as match_parent which fills up the layout. It should be wrap_content or use weights to better organize how it should look. At least, that's what looks wrong to me. Try swapping out match_parent to wrap_content or use weight attribute. Note that if you use weight set android:layout_height' to0dp.`
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/mainLayout"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/quoteLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<Button
android:id="#id/getMoreButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/getMore"
android:onClick="getMore" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/adLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
You have set your quote layout to match_height within another LinearLayout that also matches height. Your button layout and adLayout are simply off the bottom of the screen.
To fix this, I would use layout weights like so:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/mainLayout"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/quoteLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<Button
android:id="#id/getMoreButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/getMore"
android:onClick="getMore" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/adLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</LinearLayout>
Notice that I have changed layout_height to 0dp and added a layout_weight tag. This tag makes it so that your layout will adjust to a certain percentage of the height based on the values entered.
You could also use wrap_content for height.
How to make sure my Imageview fit in TableLayout? Mine can't be fit like this one.
Mine is like this
My code
<?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="match_parent"
android:orientation="vertical"
android:scrollbars="none" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/kelas_mengaji" />
</LinearLayout>
</TableRow>
</TableLayout>
</ScrollView>
Add this to the ImageView
android:adjustViewBounds="true"
I have just implemented Tabs with swipe using FragmentTabHost in android. But there's an issue in the layout. When i running my application i get the below output. The swipe is only work for the below part
I Want something like
The code of XML i'm using is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>