Reputation: 173
I want the text to appear on the button and not under it.And How can I give more weightage to the TextView rather than the Button background Colour.I was building an App TicTacToe and I came across this Issue.I'm not able to solve it.Can someone please guide me?
Activity(MainActivity.java):
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends
AppCompatActivity implements View.OnClickListener {
TextView textone;
Button button,buttonPanel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textone = (TextView)findViewById(R.id.textone);
button = (Button)findViewById(R.id.button);
buttonPanel = (Button)findViewById(R.id.buttonPanel);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(v.getId() == R.id.button){
textone.setText("This is not Fair");
}
}
}
Layout(activity_main.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=".MainActivity">
<Button
android:id="@+id/buttonPanel"
android:text="@string/button"
android:textSize="40sp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f4f18a"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/textone"
android:id="@+id/textone"
android:textSize="45sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button2"
android:id="@+id/button"
android:layout_marginBottom="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Upvotes: 1
Views: 63
Reputation: 25312
If you have <LinearLayout ...
as a parent of your layout, You need to add your <TextView ..
and <Button ..
like as below
<LinearLayout layout_height=".." layout_width=".." orientation="vertical">
<TextView layout_height=".." layout_width=".." id="@+id/textone"/>
<Button layout_height=".." layout_width=".." id="@+id/button" />
<!-- your other layout view -->
</LinearLayout>
2.If you have <RelativeLayout ...
as a parent of your layout, You need to add your <TextView ..
and <Button ..
as below
<RelativeLayout layout_height=".." layout_width=".." orientation="vertical">
<TextView layout_height=".." layout_width=".." id="@+id/textone"/>
<Button layout_height=".." layout_width=".." id="@+id/button" android:layout_below="@id/textone" />
<!-- your other layout view -->
</RelativeLayout>
Upvotes: 1