my textview display in emulator top..how to change into the bottom...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/tv">
<TextView
android:text="EmbDes Technologies"
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff000000"
android:textStyle="bold"
android:gravity="bottom"/>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/videoGrdVw"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
Although your question seems to be obscure, what i understand is that you want to align it to the bottom. Here is how you can do it:
Add the following property to your textview:
android:gravity="bottom"
Hope this helps. If it does, mark it as answered and do vote for it.
Regards.
well,
Button,TextView are all widget and subclasses from view
you can use textview as button easily ..
i.e. click responding:
TextView tt=(TextView)findViewById(R.id.tt1);
tt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//here I change background color when press on textviw element
v.setBackgroundColor(Color.RED);
}
});
I hope this helps you,
if not ask exactly what are you going to do..
good luck
Mohammed,
using the relative layout, align one view to the top with a bottom margin equal to the height of the bottom view and align the bottom view to the bottom of the relative layout...
Related
Im trying to find a method to freeze the activity state, but without success.
Im creating a game, and I want to add a pause button. When the user clicks, the activity should freeze with the components, and when click again, keep from where it was before. Is that possible to do that?
Please check the solution it can be helpful for u. As u want to freez the screen for sometime than u have to play with View Visibility.
For it u have to create the view like i have use the rlView in my below layout. Visible it when u want to freez the screen.And again when u want to remove it than set the visibility of view is gone..
We can manage the View visiblity like below:-
RelativeLayout rlView= (RelativeLayout) findViewById(R.id.rlView)
YOUR_BUTTON_CLICK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(rlView.getVisibility()==View.VISIBLE)
{
rlView.setVisibility(View.GONE);
}
else {
rlView.setVisibility(View.VISIBLE);
}
}
});
}
Please check the layout:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
HERE IS YOUR WHOLE LAYOUT VIEW
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:background="#android:color/transparent"
>
</RelativeLayout>
</RelativeLayout>
I have the following layout (cut down to a minimal example)
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="#+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/free_text_default_bg"
android:gravity="center_horizontal"
android:padding="#dimen/free_text_padding"
android:text="background element is a video view" />
</RelativeLayout>
The problem is, that if I move the EditText around (it has a drag listener attached to it), it dissapears at a certain point of the screen as you can see in this screenshot.
The problem seems to only appear when I have a VideoView. Even if I don't show a video.
When I replace it with e.g. an ImageView there is no problem at all.
So my question is, what's happening and how can I resolve this?
Thanks for your time!
UPDATE 1: This only happens if the VideoView has
android:layout_height="match_parent"
when I set it to some "dp" value everything works just fine...
I did not find a solution to my question jet but I have found a workaround:
Once the layout is finished, I get the height from the parent container, subtract 1px and set this as new height for the video view.
The 1px is barely visible...
Here is the code:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
ViewGroup.LayoutParams layoutParams = videoView.getLayoutParams();
layoutParams.height = parentView.getHeight() - 1;
videoView.setLayoutParams(layoutParams);
}
I have a relative layout:
RelativeLayout battle_layout = (RelativeLayout) findViewById(R.id.battle);
I need to attach here a child (a JPG image from resources/drawable).
I was writting in c# and javascript earlier, but here it's a bit harder to accomplish :)
Is there someone who could help me? Thanks!
Maybe you can use one of these options. programmatically or in xml:
Add a ImageView to your layout
Set the image as background of your layout
Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/YOUR_IMAGE">
<ImageView
android:src="#drawable/YOUR_IMAGE"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Code
ImageView imageView = new ImageView(this);
image.setImageResource(R.drawable.YOUR_IMAGE);
battle_layout.addView(image);
I want to make an app with a login activity/layout similar to what Facebook app has. What I mean is when text field is focused soft keyboard pushes the entire view up but not squashing a logo. I have tried android:windowSoftInputMode="adjustPan/adjustResize" but it is not what I was trying to achieve.
I found this question on SO perhaps it will make things clearer, but it has no solution to the problem.
I have also tried various layouts types but it soft keyboard only pushes the focused < EditText > up. Please guide me.
UPDATE:
<?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:background="#DDDDDD">
<RelativeLayout
android:height="0dp"
android:layout_weight="1"
android:layout_height="0dp"
android:layout_width="fill_parent"
android:background="#ff0000">
<ImageView
android:layout_centerVertical="true"
android:layout_height="fill_parent"
android:layout_width="fill_parent"></ImageView>
</RelativeLayout>
<RelativeLayout
android:height="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="fill_parent"
android:background="#00ff00">
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#0000ff"
android:height="0dp" >
<Button
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Log in"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="4dp"
android:hint="password"
android:inputType="textPassword" >
</EditText>
<EditText
android:id="#+id/editText1"
android:hint="login"
android:padding="4dp"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" ></EditText>
</RelativeLayout>
</LinearLayout>
UPDATE working solution
I can't paste here the entire xml file, but the structure should be enough.
Based on Gabe Sechan's answer.
Layout{
Layout top weight 1
Layout mid weight 1
Layout bot weight 1
}
Child layouts have set to:
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" // should be changed accordingly to your layout design.
And here is a Java code for the activity(keyboard up/down):
View top, mid, bot;
final View activityRootView = findViewById(R.id.loginLayout);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView()
.getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { //keyboard up
mid.setVisibility(View.INVISIBLE);
top.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 0f));
bot.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 1f));
} else {// keyboard down
// v.setVisibility(View.VISIBLE);
mid.setVisibility(View.VISIBLE);
top.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 2f));
bot.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 3f));
}
}
});
On keyboard up you need to change weights accourding to keyboard up design and on keyboard down change back to the default(layout that you've set via xml/java). I've tested the code on 2.3.x and up.
And don't forget to use android:inputType="textFilter" for the login&password EditText's to remove suggestions on input and save some pixels. In your manifest for the activity android:windowSoftInputMode="adjustResize|stateHidden". stateHidden is used so that keyboard won't be up when activity loads. Hope it helps. Good luck.
They're doing it with relative layouts, adjustResize, and android:layout_centerVertical. Basically, they have a linear layout for their main layout, with 3 equally weighted relative layouts inside of it. Each is set to 0dp height, so they take up equal thirds of the screen. The top RelativeLayout holds the logo, centered vertically. The middle holds the login fields and button, centered vertically one on top of the other. The bottom one holds the copyright text, aligned to bottom. The end result is that when the keyboard comes up, the 3 relative layouts get resized to take 1/3 of the new screen. Then their elements are centered in the new screen.
Remember you need the adjustResize window mode to get this, if you use pan it will just move up and the logo will scroll off center.
In Eclipse, go to File|New|Other and in the Wizard that follows, select Android Activity, then on the next page, select LoginActivity from the list of activities. This has the exact layout you're talking about, and you can use that as a framework. It uses a ScrollView to achieve the effect you're looking for.
I already tried all things I could find (on stackoverflow and the net) but I somehow cannot set my dialog to fullscreen. It has a scrollview with a textview in it, and when there is not much text in the textview the scrollview is not fullscreen. How can I force it to be fullscreen even when there is not much text visible ?
I create the dialog like this:
final TextView box;
final Dialog info = new Dialog(cx);
final ScrollView scroll;
info.setContentView(R.layout.dialoginfo);
info.setTitle("Info");
info.setCancelable(true);
info.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
scroll = ((ScrollView) info.findViewById(R.id.scrollviewinfo));
scroll.setPersistentDrawingCache(ScrollView.PERSISTENT_NO_CACHE);
scroll.setScrollbarFadingEnabled(false);
box = (TextView) info.findViewById(R.id.infotext);
box.setText(text);
info.show();
This is the xml:
<?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:id="#+id/infolayout"
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ImageView01"
android:layout_weight="1.0"
android:id="#+id/scrollviewinfo">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/infolayout2">
<TextView android:layout_margin="5dip" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/infotext"
android:textSize="8sp"
android:text=""/>
</LinearLayout>
</ScrollView>
</LinearLayout>
It looks like your ScrollView has its height set to wrap_content, I'd first try replacing it with fill_parent.
Here are some other resources that may help you:
How can I get a Dialog style activity window to fill the screen?
I've never used the setFlags() method, so this may give you the same results. Basically try replacing
info.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
with
info.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
Alternatively, if you wanted more exact control over the height, you can create an instance of layout params, as the first answer here describes:
How to make an alert dialog fill 90% of screen size?
You can also use this code to get the screen size, if you wanted to modify it to be slightly smaller than full screen.
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
There are quite a few other ways to get the current screen size, too, this is just one example. Good luck!
Have you tried setting layout_height of the ScrollView to "match_parent" (and you can set the LinearLayout to "match_parent" too, though I don't think it's necessary)?. I'm guessing it shrinks when there isn't much text because it's set to "wrap_content". Try this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#+id/ImageView01"
android:layout_weight="1.0"
android:id="#+id/scrollviewinfo">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/infolayout2">
...
</LinearLayout>
</ScrollView>
Try wrapping your dialog custom layout into RelativeLayout instead of Linear Layout. That worked for me.