So I started using Umano's AndroidSlidingUpPanel library and it's very useful. I managed to implement ONE sliding panel from the bottom which worked very well. However I want to implement two Sliding panels (top and bottom) such as this:
This is what I have so far:
<?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ECECEC"
android:gravity="bottom"
android:orientation="vertical"
sothree:panelHeight="68dp"
sothree:shadowHeight="4dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="#dimen/feed_item_margin"
android:layout_marginRight="#dimen/feed_item_margin"
android:background="#drawable/bg_card"
android:orientation="vertical"
android:paddingBottom="#dimen/feed_item_padding_top_bottom"
android:paddingTop="#dimen/feed_item_padding_top_bottom" >
<com.krish.horizontalscrollview.CenterLockHorizontalScrollview
android:id="#+id/picture_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</com.krish.horizontalscrollview.CenterLockHorizontalScrollview>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hi"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:text="The Awesome Sliding Up Panel"
android:textSize="16sp" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout><LinearLayout>
How do I add two Sliding Panels to a view? :)
try to set the parameter rotation = "180" of
com.krish.horizontalscrollview.CenterLockHorizontalScrollview
Related
My app has a banner ad at the bottom.It takes some time load.While it loads a white space appears in its place as shown below:
How do i slove this problem.Should improve the loading speed of the banner ad or do something with my xml layout.
Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="com.example.android.gametalks.MainActivity"
>
<LinearLayout
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/no_internet_view"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Internet Connection!"/>
<Button
android:id="#+id/retry_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Retry"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_above="#id/adView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
></ListView>
</LinearLayout>
</LinearLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
You can remove android:layout_above="#id/adView from list container and add to your ListView paddingBottom = height_of_your_banner (or about it) and add android:clipToPadding="false". Now your listview will fill whole screen and if you scroll to bottom - you will be able to see al items without overlap from banner. Also you can remove odd containers from ListView so instead of:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_above="#id/adView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
></ListView>
</LinearLayout>
</LinearLayout>
Will be just:
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
I want my fragment look like it has 3 buttons that fill the screen in both vertically and horizontally on the phone. I managed to do that somehow but I can't add another row of buttons. This is my layout... what am I doing wrong?
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Scroll view contains only one direct child so you can not add second child directly you have to do following
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<!--add here second row and other continue same -->
</LinearLayout>
</ScrollView>
</LinearLayout>
NOTE: If scrollview is only one element you going to use then you can make it root layout by removing current linearlayout from root and also remove scrollview weight for same case, it is good practice to minimize the layout hierarchy to performance improvement
First Note : scroll view remove effect of weight property
Delete the scroll view element from your layout
Second note : each button make
<Button ...
android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" />
Because 0dp let the Android system calculate the height of button Equally
Hi I have a ScrollView and inside I have a LinearLayout and inside I have a buttons. I don't know how I can have this buttons always at the top when I scroll a view. Now when I scroll view a buttons disappear.
My code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:weightSum="1">
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|bottom"
android:layout_marginTop="0dp">
<Button
android:id="#+id/cpic"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:text="Zdjęcie" />
<Button
android:id="#+id/up"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:text="Wyślij" />
</LinearLayout>
<ImageView
android:id="#+id/Imageprev"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="58dp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
what I understand from your question i think you can achieve it by putting your button outside your scroll view inside XML , this would give you a fix button.
hope this helps.
I have an activity with a fragment container for showing different details of an object in my app.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<LinearLayout
android:orientation="horizontal"
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</LinearLayout>
</LinearLayout>
This works fine. Tabs are displayed properly.
Now I want to add an header line to this actitivy which shows "static" content regardless of the current fragment for the details. The header line shall be on top with the fragment-container below. So I changed the layout to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<LinearLayout
android:orientation="horizontal"
android:id="#+id/LabeledObjectHeaderInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtHeaderID"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".10"
android:gravity="right"
android:padding="10dip"
android:text="#string/txtHeaderID"
android:textSize="20sp" />
<TextView
android:id="#+id/txtHeaderIDValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:gravity="left"
android:padding="10dip"
android:text="test"
android:textSize="20sp" />
<TextView
android:id="#+id/txtHeaderName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:gravity="left"
android:padding="10dip"
android:text="#string/txtHeaderName"
android:textSize="20sp" />
<TextView
android:id="#+id/txtHeaderNameValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50"
android:gravity="left"
android:padding="10dip"
android:text="test"
android:textSize="20sp" />
</LinearLayout >
<LinearLayout
android:orientation="horizontal"
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
>
</LinearLayout>
</LinearLayout>
My problem is now, that only the header is shown, but not the content of the fragments. I only changed the layout file up to now (as you can see by the "test"-texts), but no other code.
What am I doing wrong and where is my mistake?
Try this
In your container LinearLayout you have android:orientation="horizontal" which shows its first child LinearLayout i.e the Header, but hides its second child LinearLayout i.e the content to the right.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<!-- Inner Layouts -->
</LinearLayout>
Change it to android:orientation="vertical".
<?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"
android:layout_gravity="center">
<!-- Inner Layouts -->
</LinearLayout>
just make the orientation in your main layout vertical and it will work fine.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
Because you are making its orientation horizontal, the fragments layout goes to the right.
Please have a look at the following code
<ScrollView 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"
tools:context=".DisplayResult" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
>
<ImageView
android:id="#+id/zodiac1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/aries"
/>
<TextView
android:id="#+id/orTxt"
android:text="Or"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/zodiac2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gemini"
/>
</LinearLayout>
</ScrollView>
I want this "LinearLayout" to be centered at the top. Not in the exact center of the device screen. How can I do it? Please help!
EDIT
What I mean is, I want the things inside linear layout to be appeared at the top of the application. They should be centered in that space. If I use RelativeLayout, this is what I do
android:layout_centerHorizontal="true"
android:layout_alignTop="true"
If you want to duplicate RelativeLayout's alignTop, try:
<ScrollView 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"
tools:context=".DisplayResult" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal" >