Android: How to add images/ImageView in on an EditText - android

I'm currently trying to build a Note making app and one of its feature is supposed to be Opening the camera,taking an image and I should display this image on the EditText along with other Text which is already present in the EditText.
I know how to Open the camera,saving the image and stuff but How do you add the Image I captured below/above an EditText?
I believe that we need ImageView to display images but how do I incorporate this in my app along with the EditText?
Something like this...
Kindly point me to anything which helps me in finding how to do it since I'm unable to find anything useful.

<LinearLayout orientaion:vertical >
<EditText>
</EditText>
<ImageView>
</ImageView>
</LinearLayout>
If you want many ImageViews,You can create many at run time while taking photo.
ImageView view = new ImageView(context);
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Linear_layout.addView(view, lp);

You should be able to add an image directly into the editText by using html tags to do so. I'm not entirely sure on how to acquire uri reference to the image, but i assume thats not too hard.

Wrap the EditText in a LinearLayout, then add the ImageView to that LinearLayout.
If you define it in xml, it should look like this:
<LinearLayout ...>
<EditText .../>
<ImageView .../>
</LinearLayout>

Related

Android autoscrolling text view

I would like to implement a auto scrolling text view in a native Android app.
Something like a vertically scrolling marquee. The idea being that it looks something similar to an autocue, the text will remain static and scroll once more text has been provided.
I am happy to work out the logic of scrolling the text when new text arrives. I am just looking for ideas on how to have that text feed/scroll effect animation.
Thank you
Maybe start here to make the textview scrollable:
Making TextView scrollable on Android
After that, you should be able to use an object animator, such as:
ScrollTo(0,250) with animation Android ScrollView
Do like:
in XML:
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0.0dp"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:maxLines="5" />
And in java:
textView.setMovementMethod(new ScrollingMovementMethod())
You Just check it and refer this answer.
Android automatic horizontally scrolling TextView
I think you want solution like this. for auto scrolling TextView.
there is many other solutions also which working with programmatic to scroll String in your TextView area.
auto-scrolling TextView in android to bring text into view
Automatic horizontal scroll in TextView
Refer this links and get Solution as per you want.
Thanks for this question's owners and accepted Answer givers.

Non scrollable textview in android

I have a textview configured in my XML as below.
<RelativeLayout>
<!-- more views here like ImageView and other TextView-->
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="4"
android:textIsSelectable="false"
android:autoLink="web|phone|email"/>
</RelativeLayout>
The content for this view could be text and may also contain HTML content. Hence I have set autoLink to true. The issue is, if either the autoLink or the textIsSelectable is true, then the textview starts to scroll similar to(MovementMethod) when its content is more than 4 lines. I am looking for a way to stop/disable this textview scrolling.
I tried to disable the scrolling using setEnable(false) for the text view, however, all the links in the textview could not be clicked thereafter.
I think there has to be a straight forward way to achieve "non-scrollable textview" which may contain HTML content in them.
I think you can add the attribute android:nestedScrollingEnabled="false" to any View child. At least, I use android:nestedScrollingEnabled="true" to make my TextViews scrollable. Hope this solves your problem.
BTW, why are you trying to display a clickable link when you can't even scroll to look at the entire link? Just asking out of curiosity.
set ellipsize to the text view so text can't be greater than 4 lines
may be this is solution for you
Try changing 'Relative Layout' to 'Table layout'... If this doesn't work then try to set appropriate padding and margin for Textview and other widgets.

Android Layout Issue

Hi I'm having a daft problem with my android application.
Currently it looks like this:
Is there a way of making the button go to the bottom in the middle? I've tried messing around but same effect. Also tried changing the fill_parent/wrap_content, relative/linear layouts and gravities.
This is the screenshot of the .xml file
many thanks.
There are a couple things you can do to get this, with the relative layout you're using this would work. Add these lines to your button section
android:layout_below="#+id/android:empty"
android:layout_alignParentBottom="true"
android:layout_alignParentCenter="true"
Add these two attributes to your Button
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
and these one to your textview:
android:layout_above="#id/insertion"
android:layout_height="fill_parent"
Read the API reference here:
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
May be you want to use a linear layout instead of the relative one...
With the LinearLayout you can place your item without thinking on their relative position.
You can place a vertical linear layout and inside it another layout for the list of reminders.
<LinearLayout android:orientation="vertical">
<ListView android:width="fill_parent"android:weight="2" />
<Button android:width="wrap_content" android:weight="1" />
</LinearLayout>
With weight option, you can choose to make the Button to be painted before the ListView.
EDIT: Reading other answers, I'm considering if you really need a RelativeLayout to place a button under a listview. I think you should learn how to handle simple view before to start using something more complex. If LinearLayout solve your problem, why don't use it? This is a personal observation...

How to show a picture?

I'm having a problem calling a picture to view. In my app after they click the button i want to take them to a new page where it will display a picture and under it some text. For this example say i want a pic if dog to be at the top of the page then under it say i want something like the breed and the cost of breed. Can anyone help me?
Use this XML for your page what will display the image:
<ImageView
android:id="#+id/image"
android:src="src"
/>
<TextView
android:text="image text"
android:layout_below ="#id/image"
/>
Of course, add more options to the views
Some good references:
http://developer.android.com/reference/android/widget/ImageView.html
http://developer.android.com/reference/android/widget/TextView.html
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
Use ImageView.
Also for other questions like this, I highly recommend reading the User Interface section of the online Android Developer's Guide.
In a layout XML, put a LinearLayout, oriented vertically, containing first an ImageView widget then a TextView widget. You can set the text using TextView#setText(String) and the image using ImageView#setDrawable(...).
This layout will be used by an activity that reads the Extra information (for example the text to show and the image URL or the image path on the SDCard) when it starts.
You should read more about Views on the Android developer's guide as advised by Shawn Lauzon.
write the above code in your .xml
<ImageView android:id="#+id/img"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center">
</ImageView>
and add this line in your .java class
img = (ImageView) findViewById(R.id.img);

dynamic layout change during runtime

for an application I need to place some objects at the exact position that I want to have them and therefore I need to use AbsoluteLayout this time.
I want to add buttons dynamically exactly like in the following XML - but during runtime.
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/backbutton"
android:text="TEST123"
android:layout_x="120px"
android:layout_y="120px"
android:layout_width="100px"
android:layout_height="100px" />
</AbsoluteLayout>
How can I archive this? I tried it with the following code to add a button, but I haven't found a function so far to set layout_x and layout_y. How can I do this? Thanks.
AbsoluteLayout al = new AbsoluteLayout(this);
Button t = new Button(this);
t.setHeight(300);
t.setWidth(300);
t.setText("TEST123");
// x y ???
setContentView(al);
When you add the view to the layout, you can provide LayoutParams, which is where you specify layout information for the view.
However, AbsoluteLayouts are deprecated, with good reason. How are you going to handle different screen sizes and resolutions? You should be able to create the layout you are looking for with a combination of the non-deprecated layout objects. See developer docs as a starting point.
If you describe your goals in more detail, someone should be able to help you select the proper layout.
You should try with Canvas methods.
onDraw(Canvas canvas)
Using canvas - will not create actual buttons, but you can work with images.
Also have a look to these link : Android drawing button to canvas with custom view?

Categories

Resources