Adding containers and action bar to an Android Activity. - java

I am trying to add action bar on top, and two containers below the action bar, each of the containers I want to have 80% of width and 20% of width.
Here is my XML file which is not working:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hany_action_bar.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:id="#+id/menu_container"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:weightSum="20"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/main_container"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:weightSum="80"
android:orientation="horizontal" >
</LinearLayout>
</FrameLayout>

Can try like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
tools:context="com.example.hany_action_bar.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:id="#+id/menu_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1.6"
android:background="#000"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/main_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.4"
android:background="#fff"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>

Related

Tab Activity Swipe

There is a tabhost that contains 3 elements. How to make swipe between them?
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_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" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tasks1">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tasks2" >
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tasks3">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
If you alter this option does not work, then how to do this with a tabbed activity(i need to swipe between the 3 elements)? Thanks in advance.

Add TextView after LineChart

Okey guys i have LineChart made with achartengine, here is screenshot:
https://www.dropbox.com/s/yk5nipe3b6upcaa/11414548_10205801109521047_408896835_n.jpg?dl=0
1st XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:id="#+id/linearLayout1"
android:orientation="horizontal">
</LinearLayout>
<TextView
android:layout_below="#+id/linearLayout1"
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Description:"
android:textStyle="bold"
/>
<TextView
android:layout_below="#+id/description"
android:id="#+id/descriptionText"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
2ndXML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/linearLayout1" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Description:"
android:textStyle="bold"
/>
<TextView
android:id="#+id/descriptionText"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
Here is code for onCreate() method:
description=(TextView)findViewById(R.id.descriptionText);
description.setText("sadasdasdas");
setRendererStyling();
if (mChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout1);
mChartView = ChartFactory.getLineChartView(this, mDataset,
mRenderer);
mRenderer.setSelectableBuffer(100);
layout.addView(mChartView, new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
} else
mChartView.repaint();
My problem is that I want to put two TextViews after chart.I tried with this two different xml and no result.
I am only getting Description: on my activity...
EDIT FOR Dharm
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:id="#+id/linearLayout1"
android:orientation="horizontal"
android:layout_above="#+id/scrollView">
</LinearLayout>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description:"
android:textStyle="bold"
/>
<TextView
android:layout_below="#+id/description"
android:id="#+id/descriptionText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Use a RelativeLayout and arrange the graph to have its bottom align with the top of your TextViews. Your first xml is close, but it is creating a LinearLayout that fills the screen and then placing the TextView below that.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:id="#+id/linearLayout1"
android:orientation="horizontal"
android:layout_above="#+id/description">
</LinearLayout>
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description:"
android:textStyle="bold"
android:layout_alignParentBottom="true" />
<TextView
android:layout_toRightOf="#+id/description"
android:id="#+id/descriptionText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>

Changing color of TabHost/TabWidget

I'm having a really hard time changing the color of my TabWidget. I've looked at several posts and tried them out, but none of them worked for me. I'm trying to change the default (blue) color scene to green.
Image of my app
My xml code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="#+id/relativeLayout">
<TabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tabHost"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:tabStripEnabled="false">
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="#+id/listFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
The way to change the color of the tabs programmatically is by using
for(int i=0;i<mTabHost.getTabWidget().getChildCount();i++)
{
mTabHost.getTabWidget().getChildAt(i)
.setBackgroundColor(Color.parseColor("#00304E"));
}
To change the color of the currently selected tab,
mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab())
.setBackgroundColor(Color.parseColor("#008EE8"));

Exception raised during rendering: TabHost requires a TabWidget with id "android:id/tabs"

Having an issue with Android Studio. Basically, I'm doing as it says however it's producing an error which I can't figure out.
I have tried using android:id="android:id/tabs". Alas this did not work either
Here is the XML:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".FindMyCar"
android:id="#+id/">
<TabHost
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tabHost"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="android:id_tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tabFind"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="#+id/tabRandom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
I have tried using android:id="android:id/tabs"
It should be android:id="#android:id/tabs"

Android ImageView getting over linearlayout

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>

Categories