I have read about accessing xml layout component thorugh opengl renderer and Im still cant do it.. can anyone tell me how to do it?
My xml layout is using relativelayout..
this is a part of my java class for set the renderer
GamePlayActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLSurfaceView = new GameView(this);
mGLSurfaceView.setRenderer(new GameRenderer(this,GamePlayActivity.this));
setContentView(R.layout.gameplay);
sv = (RelativeLayout) findViewById(R.id.gameviewxml1);
sv.addView(mGLSurfaceView, 0);
and this is my renderer constructor
GameRenderer.java
private GamePlayActivity gpa;
public GameRenderer(Context context,GamePlayActivity gp)
{
grContext = context;
gpa = gp;
}
I have a textview I want to change the text when renderer finish doing some animation.. I tried using this in renderer class
gpa.roll.setText("Done");
but the app crash after that.. I wonder where I was wrong?If I missimg some data that I need to show just tell me.. I`ll post it..
I don't understand why you pass in GPA, but that's okay. If you declare the SurfaceView in xml, it should be pretty easy to position everything that way. For example:
<SurfaceView
android:id="#+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/ad_detect" />
<TextView
android:id="#+id/tv_label_temp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ad_detect"
android:layout_marginRight="10dp"
android:layout_marginTop="18dp"
android:layout_toLeftOf="#+id/tv_value_temp_bkrd"
android:shadowColor="#00FF00"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="10"
android:text="#string/temp"
android:textColor="#00FF00"
android:textSize="22sp" />
Related
I'm looking for a button just like this (transparent background and when clicked it becomes gray):Image of the component
Your question is not so clear, but here is how you can create custom or style Button
I succeeded.
The solution is:
xml(button_category_template):
<?xml version="1.0" encoding="utf-8"?>
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000000"
android:textSize="20sp"
/>
java(MainActivity):
public class startActivity extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
Button btn = (Button)getLayoutInflater().inflate(R.layout.button_category_template, null);
lnr = findViewById(R.id.layoutApp);
lnr.addView(btn);
}
}
It may be possible to do it in a simpler way, but in my project I used it this way.
I've looked at this question here, however I still cannot find out what I'm doing wrong. There are no errors in Logcat and there definitely is data being passed to it to be made. Here's my setup:
This is all taking place below manually placed elements that I have placed in Android Studio. I have a ScrollView. Inside that ScrollView, I have a LinearLayout, parentLayout, that get's passed to this class. This method is supposed to add another Horizontal LinearLayout, layout, parentLayout. Then it is supposed to add a TextView, titleDisplay, and two Buttons to layout. So far I have only programmed just layout and titleDisplay. I tested it, and nothing was added. So before I program the other two buttons, I would like to know what I am doing wrong. Here's the Java Code:
public class FollowupOption {
private String displayName;
private JSONObject jsonInformation;
private Context context;
private LinearLayout parentLayout;
private LinearLayout layout;
private TextView titleDisplay;
private Button deleteButton, editButton;
public FollowupOption(String displayName, JSONObject jsonInformation,
Context context, LinearLayout parentLayout){
this.displayName = displayName;
this.jsonInformation = jsonInformation;
this.context = context;
this.parentLayout = parentLayout;
buildLayout();
}
private void buildLayout(){
//Horizontal Linear Layout to hold everything
this.layout = new LinearLayout(context);
this.layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
this.layout.setOrientation(LinearLayout.HORIZONTAL);
this.parentLayout.addView(this.layout);
//Text View Displaying title of followup option.
this.titleDisplay = new TextView(context);
try {
this.titleDisplay.setText(this.jsonInformation.getJSONObject("list").getString("title"));
} catch(JSONException e){ e.printStackTrace(); }
this.titleDisplay.setTextColor(0x8f142a); //Black
this.titleDisplay.setTextSize(18);
this.titleDisplay.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
this.layout.addView(this.titleDisplay);
}
}
Here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="38dp"
android:orientation="horizontal">
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.22"
android:gravity="center"
android:text="#string/followup_text"
android:textColor="#color/myRed"
android:textSize="18sp" />
<Button
android:id="#+id/followup_add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="#string/plus"
android:textAlignment="center"
android:textColor="#android:color/holo_green_dark"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="279dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="7dp">
<LinearLayout
android:id="#+id/followup_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/followup_new_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/new_followup_text" />
</LinearLayout>
</merge>
If someone could let me know what I am doing wrong or a good way to debug something like this, that would be appreciated.
Are you adding this.layout view to some view?
UPD: The problem is with your text color. Consider using the Color class to get color from its hex value or constants from that class.
Does your XML view (without the addition of the dynamic layout) take up the entire screen?
The new LinearLayout view will be added below the button. If the button is at the bottom of the screen, the layout will be added off the screen and therefore not visible.
You should add your new layout to the scroll view instead.
I am new to Android development and I have been looking through Q's/Documentation but unable to find direction on what my end game is.
I am building what could be described as a 'content aggregator' and at current I am struggling to see how I can set an activity that proceeds a click on each position to instigate either an Instagram profile mWebView or an API call. Currently my InstagramList.java is as follows -
public class InstagramList extends Activity {
ListView list;
String[] web = {
"Kyary Pamyu Pamyu",
"Tokyo Girls' Style",
"Haruka Nakagawa",
"Nemu Yumemi",
"Moga Mogami",
"Ayane Fujisaki",
"Koda Kumi",
"Atsuko Maeda",
"Tomomi Itano",
"Haruna Kojima",
"Utada Hikaru",
"Shibasaki Ko",
"Taeyon",
"Tiffany",
"Jessica",
"Sooyoung",
"Sunny",
"Laboum",
"YeEun",
"Yubin",
"Hyelim"
};
Integer[] imageId = {
R.drawable.kyary,
R.drawable.tgs,
R.drawable.haruka,
R.drawable.nemu,
R.drawable.moga,
R.drawable.ayane,
R.drawable.koda,
R.drawable.atsuko,
R.drawable.tomomi,
R.drawable.haruna,
R.drawable.utada,
R.drawable.shibasaki,
R.drawable.taeyon,
R.drawable.tiffany,
R.drawable.jessica,
R.drawable.sooyoung,
R.drawable.sunny,
R.drawable.laboum,
R.drawable.yeeun,
R.drawable.yubin,
R.drawable.hyelim
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.instagram_main);
CustomList adapter = new
CustomList(InstagramList.this, web, imageId);
}
}
The xml for this is as follows -
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
<ImageView
android:id="#+id/img"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="50dp" />
</TableRow>
</TableLayout>
Any pointers on how best to either modify this to allow better control of these variables or on a possible solution would be greatly received. Apologies if this has been asked in a similar vein before.
I observed that you are using two arrays. In place of this you can create a class with one member as string (web) and other as int (imageId). In addition to this you can add one variable for possible action as you mention there can be different actions. In adapter you can add tag on view and click listener so you can perform different actions on different item click.
Hope I understand your problem correctly. Let me know if you need more detail.
Check out this. In onItemClick method in MainActivity do what you want.
I am doing the first experiment with Android and I have the following problem with this simple application.
Basically my application consist into an ImageView showing a background immage, a TextView showing a message and a button.
When the user click this button the text of my TextView have to change and the background immage of my *ImageView also have to change.
So this is my activiy_main.xml file containing the layout of my main activity:
<LinearLayout 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:background="#B388FF"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="#+id/android_cookie_image_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerCrop"
android:src="#drawable/before_cookie" />
<TextView
android:id="#+id/status_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="I'm so hungry"
android:textColor="#android:color/white"
android:textSize="34sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="EAT COOKIE"
android:onClick="eatCookie"/>
</LinearLayout>
And this is the code of the previous activity:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void eatCookie(View v) {
TextView messaggio = (TextView) findViewById(R.id.status_text_view);
messaggio.setText("I'm so full");
ImageView sfondo = (ImageView) findViewById(R.id.android_cookie_image_view);
sfondo.setImageDrawable(Drawable.createFromPath("#drawable/after_cookie"));
}
}
As you can see, when the user click the button it is perform the eatCookie() method that first retrieve the TextView reference and change the text of this TextView. It works fine.
Then it retrieve the reference related to the ImageView and try to change the viewed immage, I have done it by this line:
sfondo.setImageDrawable(Drawable.createFromPath("#drawable/after_cookie"));
In my project I have put the after_cookie.jpg file into the /res/drawable/ folder.
The problem is that it can't work. The default immage of the android_cookie_image_view disappear but is not replaced with the after_cookie.jpg image.
What is wrong? What am I missing? How can I fix this issue?
Try this
sfondo.setImageDrawable(getResources().getDrawable(R.drawable.after_cookie));
Use this instead.
ImageView sfondo = (ImageView) findViewById(R.id.android_cookie_image_view);
sfondo.setImageDrawable(getResources().getDrawable(R.drawable.after_cookie));
And make sure you call that eatCookie function on onCreate.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eatCookie();
}
I have enabled the built in zoom controls in my google maps application, however, it shows on my footer button panel:
I want the zoom controls to be one top of the footer button bar.
public class MinuteMapActivity extends MapActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// the methods on the map are initialised here - onCreate
zoomControls();
satelliteDisplay();
snapToMap();
}
// method for Zoomcontrols
private void zoomControls() {
LinearLayout zoomControls = (LinearLayout) findViewById(R.id.zoomControls);
MapView zoomLayout = (MapView) findViewById(R.id.MapView);
//zoomControls.addView(zoomLayout, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
zoomLayout.setBuiltInZoomControls(true);
}
XML Layout:
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="#+id/MapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0zZsLcQS5Zeiqjbo1n8-nn2CqtxKIuTq2T6bskg"
/>
<!-- set zoom controls on map at the bottom -->
<LinearLayout
android:id="#+id/zoomControls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
If I enable
//zoomControls.addView(zoomLayout, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
it crashes.
Some assistance on how I can move the zoomcontrols above the bottom bar.
I think the reason it crashes is because you are trying to assign LinearLayout parameters to a layout inside a RelativeLayout, so you would have to use RelativeLayout.LayoutParams instead.
Also, I am a bit confused as to why you are using a LinearLayout for your zoom controls instead of the pre-defined View called ZoomControls. Perhaps it would save you a bit of time?
If you want to place the zoom controls above your bottom view use
<ZoomControls
android:id="#+id/zoomControls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="#+id/buttonbar" />
assuming you call your ButtonBar view buttonbar.
May you have missed the two line of code in your
<com.google.android.maps.MapView.
so paste this two lines in it and you will got it. its working 100 percent.
android:enabled="true"
android:clickable="true"