Archive for 'Imageview'

It is not possible to add a UIImageView directly as a subView to UIWebView. So if you want to add a UIImageView object as a subview to UIWebView, use the following code.

Consider a UIWebVIew object myWebView, to which you want to add a UIImageView object, myImageView.

Now you can add myImageView to myWebView as follows :

[[[myWebView subviews] objectAtIndex:0] addSubview:myImageView]; 
// This will do the trick.

In this code, we are adding the UIImageView object to the subview of the UIWebView, which is a UIScrollView.

Incoming search terms:

  • add subview to uiwebview
  • adding subviews to uiwebview
  • how to add subview to uiwebview

The following code will make the UIImageView round cornered with border to it :

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(42, 2, 55, 26)]; // Creating a UIImageView object

imgView.image = [UIImage imageNamed:@"myImage.png"]; // Adding image to the UIImageVIew object

imgView.contentMode = UIViewContentModeScaleAspectFill; // Setting the content mode for the UIImageView

imgView.clipsToBounds = YES;



// For rounded corners:

imgView.layer.cornerRadius = 6.0; // Setting the corner radius

imgView.layer.masksToBounds = YES; // For enabling masking

 

//For adding border

imgView.layer.borderColor = [UIColor whiteColor].CGColor; // Setting the border color

imgView.layer.borderWidth = 2.0; // Setting the border width

Incoming search terms:

  • border radius mask on image in objective c
  • border radius masking on uiimage in objective c
  • set border and corner radius to uiimage in objective c
  • set corner radius and border on image in objective c
  • xcode obj c uiimageview set border and rounded
  • xcode round image
  • xcode uiimageview border

Various Layout types in Android

The most commonly used layout classes in android are:

  • FrameLayout – designed to display a stack of child View controls. Multiple view controls can be added to this layout. This can be used to show multiple controls within the same screen space.
  • LinearLayout – designed to display child View controls in a single row or column. This is a very handy layout method for creating forms.
  • RelativeLayout – designed to display child View controls in relation to each other. For instance, you can set a control to be positioned “above” or “below” or “to the left of” or “to the right of” another control, referred to by its unique identifier. You can also align child View controls relative to the parent edges.
  • TableLayout – designed to organize child View controls into rows and columns. Individual View controls are added within each row of the table using a TableRow layout View (which is basically a horizontally oriented LinearLayout) for each row of the table.

     
     

    Defining an XML Layout Resource

    The most convenient and maintainable way to design application user interfaces is by creating XML layout resources.  XML layout resources must be stored in the /res/layout project directory (or, in the case of alternative resources, in a specially named sub-directory).

     
     

    The following is a simple XML layout resource, a template with a LinearLayout containing a TextView and an ImageView, defined in XML:

     
     

    <?xml version=”1.0″ encoding=”utf-8″?>  

    <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”  

    android:orientation=”vertical”  

       android:layout_width=”fill_parent”  

       android:layout_height=”fill_parent”  

       android:gravity=”center”>  

       <TextView  

               android:layout_width=”fill_parent”  

           android:id=”@+id/PhotoLabel”  

           android:layout_height=”wrap_content”  

           android:text=”@string/my_text_label”  

           android:gravity=”center_horizontal”  

           android:textSize=”20dp” />  

             <ImageView  

                 android:layout_width=”wrap_content”  

           android:layout_height=”wrap_content”  

           android:src=”@drawable/matterhorn”  

           android:adjustViewBounds=”true”  

           android:scaleType=”fitXY”  

           android:maxHeight=”250dp”  

           android:maxWidth=”250dp”  

           android:id=”@+id/Photo” />  

    </LinearLayout>  

The following layout will change the list view with image, title and description:

//list view layout xml

<ListView android:layout_height="wrap_content"
android:id="@id/android:list"
android:fastScrollEnabled="true"
android:fadeScrollbars="false"
android:marqueeRepeatLimit="marquee_forever"
android:layout_alignParentTop="true"
android:smoothScrollbar="true"
android:cacheColorHint="#293F79"
android:divider="@color/white"
android:dividerHeight="1sp"
android:layout_width="fill_parent">
</ListView>

//list view content xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:layout_height="wrap_content"
android:padding="3dip">

<ImageView
android:id="@+id/myImg"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:src="@drawable/todo_high" />

<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">

<TextView
android:id="@+id/myListText"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_marginBottom="5sp"
android:ellipsize="marquee"
android:singleLine="true"
android:layout_weight="1"
android:gravity="center_vertical"
android:text=""
android:textSize="20sp"
android:textColor="#ffffff"
android:textStyle="bold"
/>

<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/myListDetails"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="12sp"
android:text="Date: 06-16-2011" />

</LinearLayout>

</LinearLayout>

That’s it.

 

Frame Animation in Android

I’ll discuss about creating a simple Frame animation in Android, using XML.

Create an XML file in /res/drawable/ directory in your Android project.

anim_frames.xml
<animation-list xmlns:android=”http://schemas.android.com/apk/res/android” android:oneshot=”true”>
<item android:drawable=”@drawable/f0″ android:duration=”600″ />
<item android:drawable=”@drawable/f1″ android:duration=”400″ />
<item android:drawable=”@drawable/f2″ android:duration=”400″ />
<item android:drawable=”@drawable/f3″ android:duration=”400″ />
<item android:drawable=”@drawable/f4″ android:duration=”400″ />
</animation-list>

 

Copy the images for animation (frames) into /res/drawable directory:
In this example, the frames are named as f0.png, f1.png, f2.png, f3.png and f4.png.

Structure of main.xml file.. (/res/layout/main.xml)
<?xml version=”1.0″ encoding=”utf-8″?>
<AbsoluteLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res/com.schogini.nurseryrhymesdemo”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background = “@drawable/title”
>

<ImageView
android:id=”@+id/imgFrame”
android:layout_x = “0px”
android:layout_y = “40px”
android:layout_width = “320px”
android:layout_height = “440px”
android:background = “@drawable/f0″>
</ImageView>
</AbsoluteLayout>

 

xmlAnimation.java
public class XmlAnimationDemo extends Activity {

/** Called when the activity is first created. */

AnimationDrawable frameAnimation;
ImageButton btnHome, btnReload;
MediaPlayer mp = new MediaPlayer();
Button btnStart;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Set the Window Title Off
requestWindowFeature(Window.FEATURE_NO_TITLE);

//Set Screen Orientation as Portrait
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

//Display Full Screen.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.Layout
Params.FLAG_FULLSCREEN);

//Set the lay out
setContentView(R.layout.main);

//Instantiate an Image View
ImageView imgFrame = (ImageView) findViewById(R.id.imgFrame);
imgFrame.setBackgroundResource(R.drawable.anim_frames);

//Set the animation to Frame Animation
frameAnimation = (AnimationDrawable) imgFrame.getBackground();

}

//Function to catch the key stroke and stop the program.
public boolean onKeyDown(int keyCode, KeyEvent event)
{

{

if (keyCode == KeyEvent.KEYCODE_BACK)

if( mp.isPlaying()){
mp.stop();

moveTaskToBack(true);

}

}
if (keyCode == KeyEvent.KEYCODE_HOME)
{
moveTaskToBack(false);
if( mp.isPlaying()){
mp.stop();
}

}

System.exit(0);

return true;

}

}

Compile this and run, that’s it! Try out using your own images and transition effects.

We Can Build Your App for You. Lets Get Started !