I've tried a tutorial on youtube but it doesn't work,when I click the button nothing happens.
When I press the button I want to Change the layout activity and also to be set on the new layout one random text from lets say other 10 and on this current layout I wanna have the button which will randomly change the first text to another one.
Here is what codes I've used and didn't worked out.
#I can't add the codes because It doesn't let me post it here..it says something like isn't valid but you see everything in the picture,so I did all that code and when I press on my button It doesn't doing anything,what can be the problem?and If you have any idea or if you know any tutorial to help me achieve what I said I want to do upper I would appreciate really much
#as you can see there is a string option which should give me one text of all of them when I click my button,but it doesn't
sorry for image but it seems like those codes aren't good
<LinearLayout
android:layout_width="332dp"
android:layout_height="184dp"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:layout_marginTop="48dp"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="#+id/buttonsports"
android:layout_width="match_parent"
android:layout_height="129dp"
android:background="#drawable/ft"
tools:layout_editor_absoluteX="115dp"
tools:layout_editor_absoluteY="291dp" />
<TextView
android:id="#+id/sports"
android:layout_width="216dp"
android:layout_height="117dp"
android:text="TextView"
tools:layout_editor_absoluteX="95dp"
tools:layout_editor_absoluteY="246dp" />
</LinearLayout>
this is how big my text box is,the "sports" is the id for TextView which is "abc"
In your xml you have a LinearLayout for which you have set the height to:
android:layout_height="184dp"
and inside there is a Button with height:
android:layout_height="129dp"
So for the TextView below there is left maximum 55dp but you set:
android:layout_height="117dp"
This means that at least half the TextView is not visible.
In your code you set a random text to the TextView when you click the Button.
You say that nothing happens.
Is there a case that the text is being set but you can't see it because the TextView is mostly hidden?
Change the heights of the views and you will find out.
Related
EDIT: After more testing, I believe that the problem mentioned below is occuring on click, not on disable. Researching into elevation, to see if in click possibly changes that.
I am using a constraint layout and I have two buttons that contain images.
One of them is disabled temporarily or permanently when clicked by the user.
The problem? The second button (which should stay at the back) ends up covering the other newly disabled button.
I've tried searching for anything concerning this but couldn't find anything to help me solve this. I've also tried using an ImageView for the button that should stay underneath, but also didn't work.
// the button that should stay underneath
<Button
android:id="#+id/bg_pup_img"
android:contentDescription="#string/pup2_desc"
android:layout_width="0dp"
android:layout_height="400dp"
android:layout_marginTop="120dp"
android:scaleType="fitEnd"
android:background="#drawable/pup2"
android:enabled="false"
android:clickable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/end_game"
app:layout_constraintVertical_bias="1.5" />
// the button I want to stay at the top
<Button
android:id="#+id/card19"
android:layout_width="60dp"
android:layout_height="80dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:background="#drawable/blank_card"
android:tag="19"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/card15" />
Try adding android:visibility="" to 'gone' or 'invisible'
Making you button disable will put it to background.
if i understood right , you want to show a button when a user click another one , if this is the case , why don't you make the second button "invisible" after the user clicks
I seemed to have fixed my problem.
I'm not exactly sure how elevation works on click, but when ever I clicked the "top" button, it would go below the "bottom" button.
I made the elevation of the "bottom" button to be 0dp while the "top" button is 1dp. Now I no longer have that problem.
I know this question is repeated but I don't get the Proper solutions.
I want to bring arrow closer to the Spinner (That means i want to decrease the width of spinner and decrease the space between text and down arrow) I have used default spinner. How can I do that? Please, guide me to get Solution.
Here is the XML code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/relativeLayout15">
<Spinner
android:id="#+id/languageDropdown"
style="#style/SpinnerTheme"
android:layout_width="66dp"
android:layout_height="wrap_content"
android:entries="#array/Languages" />
</RelativeLayout>
As i am understanding your question, many time we face requirement to customise spinner UI and it is too tough to achieve this. I generally use this solution for such situations:
Solution: Hide your actual Spinner and show a TextView which just looks like our desired Spinner, Please have a look at below image for better understanding:
In above image I have created a phone number field where I am getting country code from user using Spinner. I created a TextView having text as country code with drawable[right] of down arrow. Please check below XML code for better understanding:
In above image Spinner width is 0dp so your Spinner will not be visible. Just remember one thin you have to handle click event of TextView and call performClick() method for Spinner. Please refer below image for this code:
On the click event of your TextView, just follow below way:
textViewLabelCodeRegister.id -> {
spinnerCountriesRegister.performClick()
}
That's It.
Make PopupWindow instead of Spinner.
I am trying to make a layout like Telegram message box in android.
When the text is short the message and time are aligned in one single line as follows:
But when the message text is longer the time text view is pushed to the bottom of message like this:
How can i achieve this?
P.s. I tried to read the telegram source but wasn't able to figure it out. And i tried to get the size of my text view in adapter but wasn't successful.
Your shown example looks like a RelativeLayout with two TextViews in it (first TextView top-left and second TextView bottom-right).
It should be possible to accomplish this by using a RelativeLayout and two TextViews. The TextViews should be positioned correctly based on the length of the text (the second TextView displaying time should be always in bottom-right corner).
Actually they are not aligned in one line... :D I think you can achieve this by wrapping your TextView for time in RelativeLayout like that:
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/background"
android:padding="10dp" >
<TextView style="#style/TextView_port"
android:id="#+id/text"
android:text="Text" />
<RelativeLayout style="#style/LinearLayout"
android:layout_below="#id/text"
android:layout_margin="10dp"
android:gravity="right" >
<TextView style="#style/TextView_port"
android:text="3:59pm"
android:textColor="#73B661" />
</RelativeLayout>
</LinearLayout>
Here i found a trick to set your text alignment to justify:
https://dzone.com/articles/android-%E2%80%93-how-display
EDIT
I finally came up with the solution - the edited code above is for short texts. Check programatically the length of the text and if it is more than 20 for example set orientation of the Linear to vertical and only top margin of the time TextView to -20 - I'll update my answer later if you don't know how :)
I have the below xml code which i use to display inside a Dialog. The problem is that the letter "E" in "Easy" is displayed under the radio button itself. So it's not visible. Why is that? The rest are shown correctly, on the right side of each corresponding RadioButton.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radioBtnEasy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Easy"
android:layout_weight="1" />
<RadioButton
android:id="#+id/radioBtnMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:checked="true"
android:text="Medium"
android:layout_weight="1" />
<RadioButton
android:id="#+id/radioBtnHard"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hard"
android:layout_weight="1" />
</RadioGroup>
EDIT
At Padma Kumar's request, i post the rest of the code. This is how i display the dialog. I made the dialog's width to fit the screen's width, and not wrap around the content.
I removed this, but it still displayed the Easy text incorrectly.
//Define a new dialog window
Dialog dialog = new Dialog(this);
//Load the predefined layout onto this dialog
dialog.setContentView(R.layout.new_session_dialog);
//Set title of dialog
dialog.setTitle("Create new session");
//Set the width of the dialog to fill the width of the screen
dialog.getWindow().setLayout(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
//Show the dialog
dialog.show();
use the android:ems attribute it but manage your text on all density device
The 0dp width is most likely the issue,
Otherwise if only the first character "E" is not being displayed, put a space before Easy.
Ex)Instead of "Easy" put " Easy"
Thanks for posting this question. I ran into the same problem: the icon in the first radio button stomped on the first letter in the text following it. I am using the Android 1.6 emulator. After I install my app, start my app and display the radio group, I see the problem. However, when I use Back key to take me back to the Home screen and start my app and display the radio group again, I don't see the problem!
Try to remove layout_weight=1 first and put fill_parent on RadioButton width. Then do necessary adjustment.
I am trying to port my WP7 app to android.
Does anyone know how I can layout the text on a single button so that some text appears aligned left and other text appears aligned right? (See below). I need access to be able to dynamically change the percentage number on the right side using code but the text on the right is just static.
Anyone know the answer to this?
The image is here:
http://i.imgur.com/zW7YV.png
Yes you could make it two buttons.
Remove all padding and margin from between them.
Set the same background drawable.
And just ensure when the left is clicked it invokes the right's onPress method (so it looks as if they depress together).
Or wrap the buttons/imageviews/textviews in a layout and perform the onClick on that.
I would use a RelativeLayout for this.
<RelativeLayout
android:width="fill_parent"
android:height="wrap_content"
android:clickable="true"
android:background="#18a2e7"
android:padding="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Something" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_align_parentRight="true"
android:text="0%" />
</RelativeLayout>