How to get 2 images attached to layout bottom - android

I want to attach 2 images
1st at left bottom corner and other on right bottom corner
but I want that images to be hardcore in bottom so that if I scroll the page the images should remain at the same place

Dynamically ,i am succesful to answer my own question so i m hereby putting the code for all the user and it works so have the code and enjoy
LinearLayout llMain=new LinearLayout(this);
llMain.setOrientation(LinearLayout.VERTICAL);
llMain.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
llMain.setBackgroundColor(Color.WHITE);
LinearLayout llLsView=new LinearLayout(this);
llLsView.setOrientation(LinearLayout.VERTICAL);
llLsView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,1.0F));
//llLsView.setPadding(0,0,0,20);
LinearLayout llImage=new LinearLayout(this);
llImage.setOrientation(LinearLayout.HORIZONTAL);
llImage.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
llImage.setBackgroundColor(Color.BLACK);
LinearLayout llHome=new LinearLayout(this);
//llHome.setOrientation(LinearLayout.HORIZONTAL);
llHome.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT,0.5F));
llHome.setPadding(0,0,5,0);
llHome.setGravity(Gravity.RIGHT);
ImageView imgHome=new ImageView(this);
imgHome.setImageResource(R.drawable.home);
llHome.addView(imgHome);
LinearLayout llBack=new LinearLayout(this);
//llBack.setOrientation(LinearLayout.HORIZONTAL);
llBack.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT,0.5F));
llBack.setPadding(5,0,0,0);
llBack.setGravity(Gravity.LEFT);
ImageView imgBack=new ImageView(this);
imgBack.setImageResource(R.drawable.back);
llBack.addView(imgBack);
llImage.addView(llBack);
llImage.addView(llHome);
llMain.addView(llLsView);
llMain.addView(llImage);
setContentView(llMain);

Something like:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/nvContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
<ImageView
android:id="#+id/nvContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>

<RelativeLayout >
<ScrollView >
</scrollView>
<RelativeLayout android:layout_alighParentBottom=true abdroid:backgrond=#color/transparnt">
<Button >
</Button >
<Button android:layout_alighParentRight=true>
</Button >
<RelativeLayout >
</RelativeLayout >

Related

show Imageview at distance 30% from top of the screen android

I have a splash screen which displays the app logo in Imageview at center of the screen .
I need to show the imageview at a distance 30% from the top of the screen , so that the 70% of the screen at bottom looks empty
I have idea about padding , but don't know how to use %( percentage ) with this condition
<ImageView
android:id="#+id/img_splashlogo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="SplashImage"
android:layout_margin="20dip"
android:src="#drawable/app_logo_splash" />
here is the code that you can use putting the image in the linear layout and then use this code
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 0);
Button okButton=new Button(this);
okButton.setText("some text");
ll.addView(okButton, layoutParams);
try 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:background="#drawable/app_splash" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.30"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/img_splashlogo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="SplashImage"
android:layout_margin="20dip"
android:src="#drawable/app_logo_splash" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_width="0.70"
android:background="#android:color/transparent"/>
</LinearLayout>

Framelayout Progressbar problems

Hi I want to make a Progressbar with Framelayouts(one red the other green).
My problem is when I make one bigger, the other Framelayout wont move along. They overlaps.
I have tried to with LayoutParams but it does not work.
green.setScaleX(greenscale);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50,50);
params.addRule(RelativeLayout.RIGHT_OF, green.getId());
red.setLayoutParams(params);
greenscale=greenscale+5;
xml-File
<FrameLayout
android:id="#+id/progresswhite"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#CFCFCF" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/progressgreen"
android:layout_width="10dp"
android:layout_height="10dp"
android:background="#33CC33" >
</FrameLayout>
<FrameLayout
android:id="#+id/progressred"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/progressgreen"
android:background="#C12E2E" >
</FrameLayout>
</RelativeLayout>
</FrameLayout>
I want it to look like this below:
greeen=#
red=-
##-------
(green.setscale(greenscale)) (greenframe is now bigger)
######------
You should use LinearLayouts. FrameLayout draws its children one on top of another

ImageButton Position programmatically

I'm using XML for the layout but I need to programmatically position the ImageButton. Can anyone gives me an idea how to do it?
XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainScreenLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="#+id/mainScreenImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/screenimage"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/titleview"
android:background="#00000000"
android:adjustViewBounds="true"
android:src="#drawable/buttonstart"/>
</FrameLayout>
First of all, wrap the ImageButton with a FrameLayout as
....
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/titleview"
android:background="#00000000"
android:adjustViewBounds="true"
android:src="#drawable/buttonstart"/>
</FrameLayout>
....
This is not a must, to be a FrameLayout. Just wrap the image with some layout. But for other layouts, positioning with X and Y will vary.
Now, I can change the position of ImageButton as,
FrameLayout mFrame=(FrameLayout) findViewById(R.id.frameLayout1);
mFrame.setPadding(fromLeftX, fromTopY, fromRight, fromBottom);
i think LayoutParams will work fine
try this code
Button button = (Button)findViewById(R.id.my_button);
AbsoluteLayout.LayoutParams absParams =
(AbsoluteLayout.LayoutParams)button.getLayoutParams();
absParams.x = myNewX;
absParams.y = myNewY;
button.setLayoutParams(absParams);
and if you want to set image on it use setBackgroundResources property
button.setBackgroundResource(R.drawable.new_image);

Filling HorizontalScrollView from right

I programmatically add some text view to a linear layout starting from right, so put
<LinearLayout
android:id="#+id/results"
android:layout_width="wrap_content"
android:layout_height="30sp"
android:layout_gravity="right"
android:orientation="horizontal"
android:paddingLeft="12sp"
android:paddingRight="12sp" />
and coded
LinearLayout results= (LinearLayout)findViewById(R.id.results);
TextView res = new TextView(this);
res.setId(resultsCounter );
res.setText(evaluated);
...............
results.addView(res);
and this works fine but I can't add indefinitely new items, so I added an horizontal scroll view
<HorizontalScrollView
android:id="#+id/scrollresults"
android:layout_width="fill_parent"
android:layout_height="35sp"
android:layout_marginRight="12sp"
>
<LinearLayout
android:id="#+id/results"
......
</HorizontalScrollView>
but filling LinearLayout I can scroll to right only, so I lost leftmost items

ViewFlipper with a variable number of liniar layout

In my app I need to use ViewFlipper for Switching screens by dragging over the touch screen. I have a ListView that contains some items. When a item is select I must to display some images. The problem is that the number of images is different from one item to another. So I think that I must create the LinearLayout and the ImageView programatically. Is it possible what I am tring to do?
Thanks in advance..
Here is the code I tried :
<?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" android:background="#000000"
android:id="#+id/layout_main">
<ViewFlipper android:id="#+id/details"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</ViewFlipper>
</LinearLayout>
and on Oncreate() method :
for (int i = 0; i < jArray.length(); i++) {
LinearLayout l=new LinearLayout(this);
l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
l.setBackgroundColor(0xFFFFFFFF);
l.setOrientation(LinearLayout.VERTICAL);
ImageView img = new ImageView(this);
img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
//ImageView img1 = (ImageView) findViewById(R.id.photo1);
Drawable image1 = ImageOperations(getBaseContext(), url[i]);
img.setImageDrawable(image1);
l.addView(img);
}
but nothing happens. I see only a big black screen.
I exactly didnt understand what you saying but i worked on ViewFlipper before. There am using Four linear layouts as childviews for ViewFlipper which in xml. (where as firstly i tried to add listviews direclly as childviews but adding linearlayouts will make easier)
and added listviews,imageviews like you said to corresponding linearlayouts from java code.
and it worked .
Hope it helps.
Here my code i used for xml :
<RelativeLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tabrelay"
android:gravity="center_horizontal"
>
<ViewFlipper android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="#style/FlipperMargins.flipper"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:id="#+id/list1"
android:listSelector="#color/sprgreen"
android:drawSelectorOnTop="true"
android:background="#drawable/deckbackn"
style="#style/Webview.view"
/>
<LinearLayout
android:layout_width="#dimen/webViewWidth"
android:layout_height="#dimen/webViewHeight"
android:layout_gravity="center"
android:divider="#color/grey46"
android:dividerHeight="1dp"
android:id="#+id/list2"
android:background="#drawable/white"
style="#style/Webview.view"
/>
<LinearLayout
android:layout_width="#dimen/webViewWidth"
android:layout_height="#dimen/webViewHeight"
android:layout_gravity="center"
android:orientation="vertical"
android:id="#+id/list3"
android:listSelector="#color/sprgreen"
android:drawSelectorOnTop="true"
android:background="#drawable/commentsbg"
style="#style/Webview.view"
/>
<WebView
android:id="#+id/helloWebView"
android:layout_width="#dimen/webViewWidth"
android:layout_height="#dimen/webViewHeight"
android:layout_gravity="center"
android:background="#drawable/white"
style="#style/Webview.view"
/>
</ViewFlipper>
</RelativeLayout>
after that you can get Ids of linearlayouts from xml and add whaterver you want listviews etc from java..,,

Categories

Resources